How to get features by attribute
JerryLia
Global Mapper User
Hi,Mike,
I have to disturb you again.
First,I meet a new question that how to get features by attribute,I did not find the right function to do that.
Sectond,I cannot render a layer or a feature in the layer,my code such as :
// Draw the layers to the bitmap
if ((clsGlobalVARS.CurrentViewRect.MaxX > clsGlobalVARS.CurrentViewRect.MinX) &&
(clsGlobalVARS.CurrentViewRect.MaxY > clsGlobalVARS.CurrentViewRect.MinY))
{
IntPtr Hdc = graphics.GetHdc();
IntPtr LayerPtr = new IntPtr(0); // Set layer pointer to null so that all layers are drawn
LastGMError = GlobalMapperDLL.GM_DrawLayer(Hdc, LayerPtr,
ref clsGlobalVARS.CurrentViewRect,
0, 0,
BackGroundBitmap.Width,
BackGroundBitmap.Height);
GM_AreaStyle_t lt_AreaStyle;
AreaFeatureClass_t16 areaFC = (AreaFeatureClass_t16)LayerPtr.ToInt32();
LastGMError = GlobalMapperDLL.GM_GetAreaFeatureClassDrawStyle(areaFC, out lt_AreaStyle);
lt_AreaStyle.mBrushColor =(UInt32) Color.ForestGreen.ToArgb();
lt_AreaStyle.mBrushStyle =GM_BrushStyle_t16.GM_BRUSH_SOLID;
//LastGMError = GlobalMapperDLL.GM_SetAreaFeatureClassDrawStyle(areaFC,ref lt_AreaStyle);
LastGMError = GlobalMapperDLL.GM_SetAreaFeatureDrawStyle(LayerPtr, 12, ref lt_AreaStyle);
//12:I just want to find which will be rendered.
graphics.ReleaseHdc(Hdc);
//Refresh();
}
what's wrong with it?
I have to disturb you again.
First,I meet a new question that how to get features by attribute,I did not find the right function to do that.
Sectond,I cannot render a layer or a feature in the layer,my code such as :
// Draw the layers to the bitmap
if ((clsGlobalVARS.CurrentViewRect.MaxX > clsGlobalVARS.CurrentViewRect.MinX) &&
(clsGlobalVARS.CurrentViewRect.MaxY > clsGlobalVARS.CurrentViewRect.MinY))
{
IntPtr Hdc = graphics.GetHdc();
IntPtr LayerPtr = new IntPtr(0); // Set layer pointer to null so that all layers are drawn
LastGMError = GlobalMapperDLL.GM_DrawLayer(Hdc, LayerPtr,
ref clsGlobalVARS.CurrentViewRect,
0, 0,
BackGroundBitmap.Width,
BackGroundBitmap.Height);
GM_AreaStyle_t lt_AreaStyle;
AreaFeatureClass_t16 areaFC = (AreaFeatureClass_t16)LayerPtr.ToInt32();
LastGMError = GlobalMapperDLL.GM_GetAreaFeatureClassDrawStyle(areaFC, out lt_AreaStyle);
lt_AreaStyle.mBrushColor =(UInt32) Color.ForestGreen.ToArgb();
lt_AreaStyle.mBrushStyle =GM_BrushStyle_t16.GM_BRUSH_SOLID;
//LastGMError = GlobalMapperDLL.GM_SetAreaFeatureClassDrawStyle(areaFC,ref lt_AreaStyle);
LastGMError = GlobalMapperDLL.GM_SetAreaFeatureDrawStyle(LayerPtr, 12, ref lt_AreaStyle);
//12:I just want to find which will be rendered.
graphics.ReleaseHdc(Hdc);
//Refresh();
}
what's wrong with it?
Comments
-
There is not a single simple function to search by attribute. You would need to loop through the features in a layer using GM_GetAreaFeature, GM_GetLineFeature, and/or GM_GetPointFeature and look at the attribute lists yourself for each feature to find the ones matching your criteria.
For your drawing, you are passing in your layer handle as a feature classification, which is incorrect. Each feature in a layer has a classification associated with it. Those classifications are enumerated in the FeatureClass.h header file. It is one of these enumerations that you should pass to the GM_GetAreaFeatureClassDrawStyle function. For example, the AFC_UNKNOWN type will be used by default for unclassified area features.
Note that you'll also have to change the draw style for an area BEFORE calling GM_DrawLayerList if you want to actually see the change.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
I do what you say,first,I declare the GM_GetAreaFeature function such as:
[DllImport(DLLFileName, EntryPoint = "GM_GetAreaFeature")]
public static extern GM_AreaFeature_t GM_GetAreaFeature(IntPtr aLayerHandle, UInt32 aAreaIndex);
after that I count the number of polygon in a layer with it,the code is followed:
private void Menu_Counter_Click(object sender, EventArgs e)
{
bool lb_Loop = true;
GM_AreaFeature_t lt_AreaFeature;
//UInt32 i = 1;
//while (lb_Loop)
//{
// lt_AreaFeature = GlobalMapperDLL.GM_GetAreaFeature(m_OpenLayerPtr, i);
// i++;
// //if (lt_AreaFeature. == null)
// // lb_Loop = false;
//}
for (int i = 0;i< clsGlobalVARS.LayerHandles.Count; i++)
{
UInt32 j = 0;
IntPtr LayerPtr;
while(lb_Loop)
{
LayerPtr=(IntPtr)clsGlobalVARS.LayerHandles;
lt_AreaFeature = GlobalMapperDLL.GM_GetAreaFeature(LayerPtr, j);//an error ocurs:"The type signature is uncompatible with PInvoke of the method"
GlobalMapperDLL.GM_FreeAreaFeature(LayerPtr);
j++;
//How to know that the loop will be ended? }
}
}
Categories
- 12.7K All Categories
- 5.6K Features Discussion
- 342 Downloading Imagery
- 1.3K Elevation Data
- 380 Georeferencing Imagery Discussion
- 628 GM Script Language
- 53 User Scripts
- 113 GPS Features
- 414 Projection Questions
- 819 Raster Data
- 1.3K Vector Data
- 6.6K Support
- 177 Announcement and News
- 908 Bug Report
- 558 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 562 Other Discussion
- 129 GIS Data Sources
- 27 Global Mapper Showcase
- 233 How I use Global Mapper
- 107 Global Mapper Forum Website