How to symbolize a point shape file

jharding@mtaonline.netjharding@mtaonline.net Global Mapper UserPosts: 7
edited April 2014 in SDK
I would like to set a different point type or style based on an attribute in a point shape file? How do I get access to all the attribute fields in a shape file?
Thanks.

Comments

  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited February 2014
    You can use the GM_GetPointFeature function to get all of the data for a point feature, including the attribute list. Make sure to use GM_FreePointFeature when you are done with the structure so you don't get memory leaks. You can use GM_SetPointFeatureDrawStyle to change the symbology for the point feature.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • jharding@mtaonline.netjharding@mtaonline.net Global Mapper User Posts: 7
    edited February 2014
    I have the custom point style working but when I try to use a built in style the point style does not change. Please see my code below:


    for (Int32 j = 0; j < Convert.ToInt32(theLayerInfo.mNumPoints); j++)

    {

    IntPtr theInfoPtr = GlobalMapperDLL.GM_GetPointFeature(theLayerHandle, (uint)j);
    myPointStyle = (
    GM_PointStyle_t)Marshal.PtrToStructure(theInfoPtr, myPointStyle.GetType());

    //myPointStyle.mSymbolName = "SQUARE_CUSTOM_2_255_0_0";

    myPointStyle.mSymbolName =
    PointFeatureClass_t16.PFC_HOSPITAL.ToString();

    GlobalMapperDLL.GM_SetPointFeatureDrawStyle(theLayerHandle, Convert.ToUInt32(j), ref myPointStyle);

    }


    // Sets the drawing style to use for a given point feature

    [
    DllImport(DLLFileName, EntryPoint = "GM_SetPointFeatureDrawStyle")]


    public static extern GM_Error_t32 GM_SetPointFeatureDrawStyle

    (


    //GM_LayerHandle_t32 aLayer, // Layer the point is in


    //UInt32 aPointIndex, // Index of point in layer


    //ref IntPtr aPointStyle // (const GM_PointStyle_t*) New style to use for point, pass IntPtr.Zero to restore default type-based stuff




    IntPtr aLayer, // Layer the point is in


    UInt32 aPointIndex, // Index of point in layer


    ref GM_PointStyle_t aPointStyle // New style to use for point



    );

  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited February 2014
    What is PFC_HOSPITAL.ToString() going to do? I think it will convert the numeric value of PFC_HOSPITAL to a string. You actually want to set the symbol name, like:

    mPointStyle.mSymbolName = "Hospital";

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • jharding@mtaonline.netjharding@mtaonline.net Global Mapper User Posts: 7
    edited February 2014
    Thanks that worked.
  • ltl9999ltl9999 Global Mapper User Posts: 12Trusted User
    edited April 2014
    Hi, i want to change symbol for a specific point in my map (from shp file) with specific lon, lat. But i don't know how to do that. I hope you will reply soon.
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited April 2014
    You can use the GM_SetPointFeatureDrawStyle function to change the draw style for a single point feature. You can use GM_SetPointFeaturePosition to change the position of a point. To find a point by position, use GM_GetPointFeature to step through the points in the layer (make sure to use GM_FreePointFeature to free them when done) and find the position that you want.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • ltl9999ltl9999 Global Mapper User Posts: 12Trusted User
    edited April 2014
    There is no point in a map from my shape files. So i can't find any point by position. Then I decide to add point to my current layer by these lines:
    private void create_point_marker(double lat, double lon) {
    GM_PointFeature_t thePoint = new GM_PointFeature_t();
    thePoint.mFeatureInfo.mName = "Locatie contract";
    thePoint.mFeatureInfo.mDesc = null;
    // thePoint.mFeatureInfo.mClass = "PFC_TOWER";
    thePoint.mPointStyle.mSymbolName = "Fish";
    thePoint.mPointStyle.mDrawLabel = 1;
    thePoint.mPos.mX=lon;
    thePoint.mPos.mY = lat;




    // Add the point to the custom layer


    LastGMError = GlobalMapperDLL.GM_AddPointToVectorLayer(theLayerHandle, ref thePoint, 0);
    GlobalMapperDLL.GM_SetLayerEnabled(theLayerHandle, 1);
    DrawLayersToBitmap();
    }
    /////////////////
    But there's no point with a fish symbol. THen I append more lines of code to make an iteration to find if there is a point. But there's no point. (TheLayerInfo.mNumPoints=0)
    ////
    IntPtr theInfoPtr;
    for (Int32 j = 0; j < Convert.ToInt32(theLayerInfo.mNumPoints); j++)
    {


    theInfoPtr = GlobalMapperDLL.GM_GetPointFeature(theLayerHandle, (uint)j);


    GM_PointStyle_t myPointStyle = new GM_PointStyle_t();
    //Check it is inside the grid bounds




    myPointStyle = (GM_PointStyle_t)Marshal.PtrToStructure(theInfoPtr, myPointStyle.GetType());


    myPointStyle.mSymbolName = "Hospital";


    GlobalMapperDLL.GM_SetPointFeatureDrawStyle(theLayerHandle, Convert.ToUInt32(j), ref myPointStyle);
    }
    ///
    Please help me!
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited April 2014
    Did the GM_AddPointToVectorLayer return an error code? Also what is the projection of the layer that you are adding to? If the layer is not already in lat/lon (GM_PRJ_GEO) you will need to call GM_ProjectPoint to convert the point location that you are adding from lat/lon to the projection of the layer (mNativeProj in the layer info).

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • ltl9999ltl9999 Global Mapper User Posts: 12Trusted User
    edited April 2014
    There is no error when i add point to layer. I add the point after loading the shape file layer. So i think i dont have to change the projection. And i add the point to the shape file layer. Am i wrong?
  • ltl9999ltl9999 Global Mapper User Posts: 12Trusted User
    edited April 2014
    I found that in your test api function for c#. When you try to add area with points, there is no point after adding area function . Is that error with c# framework!
  • ltl9999ltl9999 Global Mapper User Posts: 12Trusted User
    edited April 2014
    I change the projection and i can a symbol point now. And then i try to add an area but it didnt work. I use this void to add area to the layer and I want to color that area, but there is no change after using this function. Please help me.
    unsafe private void create_area(GM_Point_t[] theAreaPoints)
    {


    GlobalMapperDLL.GM_Error_t32 theErrCode = 0;
    // Test creating a new area and adding it to the layer
    if (theLayerInfo.mNumAreas > 0)
    {
    // Setup a building northeast of the center point that is 20 meters high
    double theCenterX = (theLayerInfo.mGlobalRect.mMaxX + theLayerInfo.mGlobalRect.mMinX) / 2.0;
    double theCenterY = (theLayerInfo.mGlobalRect.mMaxY + theLayerInfo.mGlobalRect.mMinY) / 2.0;
    double theAreaWidth =
    (theLayerInfo.mGlobalRect.mMaxX - theLayerInfo.mGlobalRect.mMinX) / 32.0;
    double theAreaHeight =
    (theLayerInfo.mGlobalRect.mMaxY - theLayerInfo.mGlobalRect.mMinY) / 32.0;
    double theAreaCenterX = theCenterX + theAreaWidth;
    double theAreaCenterY = theCenterY + theAreaHeight;
    // Fix location of things we need pointers for
    string theAttrName = "ELEVATION";
    string theAttrVal = "20 m";
    fixed (char* theAttrNamePtr = theAttrName, theAttrValPtr = theAttrVal)
    {
    // Setup an attribute value for the elevation
    GM_AttrValueCharPtr_t[] theAttrValList = new GM_AttrValueCharPtr_t[1];
    theAttrValList[0].mName = theAttrNamePtr;
    theAttrValList[0].mVal = theAttrValPtr;


    fixed (GM_AttrValueCharPtr_t* theAttrValListPtr = &theAttrValList[0])
    {
    fixed (GM_Point_t* thePointList = &theAreaPoints[0])
    {
    // Setup the area structure
    GM_AreaFeature_t theBuilding = new GM_AreaFeature_t();
    theBuilding.mFeatureInfo.mName = "Test Building";
    theBuilding.mFeatureInfo.mDesc = "Building";
    theBuilding.mFeatureInfo.mClass = (ushort)AreaFeatureClass_t16.AFC_UNKNOWN;
    theBuilding.mFeatureInfo.mAttrList = (IntPtr)theAttrValListPtr;
    theBuilding.mFeatureInfo.mNumAttrs = 1;
    theBuilding.mPointList = (IntPtr)thePointList;
    theBuilding.mNumPoints = (uint)theAreaPoints.Length;
    // Setup the color to be solid blue
    theBuilding.mAreaStyle.mBrushStyle = GM_BrushStyle_t16.GM_BRUSH_SOLID;
    theBuilding.mAreaStyle.mBrushColor = 0x00200000;
    theBuilding.mAreaStyle.mBrushColor = (uint)128UL << 24;
    // Add the building polygon to the custom layer
    theErrCode = GlobalMapperDLL.GM_AddAreaToVectorLayer
    (
    theLayerHandle,
    ref theBuilding,
    GlobalMapperDLL.GM_AddFeatureFlags_t8.GM_AddFeature_UseDefaultStyle
    );
    }
    }
    }
    }




    }
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited April 2014
    You are passing in the GM_AddFeature_UseDefaultStyle flag when creating the area, which means that any area style provided in theBuilding.mAreaStyle is ignored and the default style for AFC_UNKNOWN is used. If you are provided a style then pass in 0 for the flags, like:

    theErrCode = GlobalMapperDLL.GM_AddAreaToVectorLayer( theLayerHandle, ref theBuilding, 0 );

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • ltl9999ltl9999 Global Mapper User Posts: 12Trusted User
    edited April 2014
    Thank you. I can color the area now. But i think the error after adding an area still exists because the count number of area is still the same(thelayerhandle.mnumareas). Can i get the id of the area i added to the layer. I don't find the function to do it. Please help me IntPtr theAreaInfoPtr, theInfoPtr; bool exists = false; for (int i = 0; i < theLayerInfo.mNumAreas; i++) { GM_AreaFeature_t theAreaFeature = new GM_AreaFeature_t(); theAreaInfoPtr = GlobalMapperDLL.GM_GetAreaFeature(theLayerHandle, (uint)i); try { theAreaFeature = (GM_AreaFeature_t)Marshal.PtrToStructure(theAreaInfoPtr, theAreaFeature.GetType()); } catch (Exception ex) { Debug.Print(ex.StackTrace); } uint m_numpoints = theAreaFeature.mNumPoints; string name = theAreaFeature.mFeatureInfo.mName; if (name != null) { // MessageBox.Show("Test"); if (name.Equals("Test")) { exists = true; break; } } } if (exists) { MessageBox.Show("exists"); } else { MessageBox.Show("not found"); }
  • ltl9999ltl9999 Global Mapper User Posts: 12Trusted User
    edited April 2014
    I can fix the error after adding area by getting the layer info again (like refresh because it not update info after adding automatically). But the line "theAreaFeature = (GM_AreaFeature_t)Marshal.PtrToStructure(theAreaIn foPtr, theAreaFeature.GetType());" still makes error because there is no area with id by i counter. So i don't know how to get the area i want. And how to know the id of all areas in the layer. Please help me
  • ltl9999ltl9999 Global Mapper User Posts: 12Trusted User
    edited April 2014
    i think the area index is not set sequentially. So i cant get the area feature by the area index.
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited April 2014
    The areas are added sequentially, so if mNumAreas is 3, then you add an area, the newly added area would be at index 3. Your loop going through the areas in a layer looks correct.

    However, do you have a license for the SDK active and set with GM_SetLicenseKey (if so GM_IsRegistered will return TRUE)? If not, the GM_GetAreaFeature (and same for line and point access) function will return a NULL pointer for anything after index 5 (GM_MAX_NON_REGISTERED_VECTOR_IDX in the GlobalMapperInterface.h header file) as you have to have a license to get at any feature. The first few features are allowed access without a license just for testing before deciding to purchase a license. So it's a somewhat common problem to encounter this error if you don't have a license or it hasn't been activated properly in the code.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
Sign In or Register to comment.