add a point feature in a custom vector layer
Hi all,
PLease let me know what I doing wrong. I try to make an application for images automation rectifying. I have loaded one image in a fake coordinate and I try to construct the GCP list reading from image the pixelX and pixelY for 4 points and after that to update the groundControl points from a feature of SHP file in good coordinates. I have problem with the create CustomVectorLayer. I dont undestand how I can have the pointer to this new created layer. I put my part of code:
double X = 0.0;
double Y = 0.0;
IntPtr WorldBoundsPtr = new IntPtr(0);
IntPtr PixelRectPtr = new IntPtr(0);
LastGMError = GlobalMapperDLL.GM_ConvertCoordPixelToGround(m_npixelX, m_npixelY, out X, out Y, WorldBoundsPtr, PixelRectPtr);
m_nGCP++;
TreeNode tn = new TreeNode();
tn.Name = "P" + m_nGCP;
tn.Text = "P" + m_nGCP.ToString() + " X:" + X.ToString() + " Y:" + Y.ToString();
currentNode.Nodes.Add(tn);
GM_Point_t aPoint = new GM_Point_t();
aPoint.mX = X;
aPoint.mY = Y;
GM_PointFeature_t aPointFeature = new GM_PointFeature_t();
aPointFeature.mPos = aPoint;
aPointFeature.mPointStyle.mSymbolName = "DOT_CUSTOM_10_255_0_0";
GlobalMapperDLLWrapper.GM_Projection_t aproj=new GM_Projection_t();
IntPtr LayerProjection;
IntPtr aLayer;
LastGMError = GlobalMapperDLL.GM_GetProjection(out LayerProjection);
aproj = (GlobalMapperDLLWrapper.GM_Projection_t)Marshal.PtrToStructure(LayerProjection, typeof(GlobalMapperDLLWrapper.GM_Projection_t));
LastGMError = GlobalMapperDLL.GM_CreateCustomVectorLayer(out aLayer, null, LayerProjection);
clsGlobalVARS.LayerHandles.Add(aLayer);
IntPtr theLayer = (IntPtr)clsGlobalVARS.LayerHandles[1];
LastGMError = GlobalMapperDLL.GM_AddPointToVectorLayer(theLayer, aPointFeature, 1);
after that code I receive an error InvalidParam.
Thanks in advance for your time.
Florian
PLease let me know what I doing wrong. I try to make an application for images automation rectifying. I have loaded one image in a fake coordinate and I try to construct the GCP list reading from image the pixelX and pixelY for 4 points and after that to update the groundControl points from a feature of SHP file in good coordinates. I have problem with the create CustomVectorLayer. I dont undestand how I can have the pointer to this new created layer. I put my part of code:
double X = 0.0;
double Y = 0.0;
IntPtr WorldBoundsPtr = new IntPtr(0);
IntPtr PixelRectPtr = new IntPtr(0);
LastGMError = GlobalMapperDLL.GM_ConvertCoordPixelToGround(m_npixelX, m_npixelY, out X, out Y, WorldBoundsPtr, PixelRectPtr);
m_nGCP++;
TreeNode tn = new TreeNode();
tn.Name = "P" + m_nGCP;
tn.Text = "P" + m_nGCP.ToString() + " X:" + X.ToString() + " Y:" + Y.ToString();
currentNode.Nodes.Add(tn);
GM_Point_t aPoint = new GM_Point_t();
aPoint.mX = X;
aPoint.mY = Y;
GM_PointFeature_t aPointFeature = new GM_PointFeature_t();
aPointFeature.mPos = aPoint;
aPointFeature.mPointStyle.mSymbolName = "DOT_CUSTOM_10_255_0_0";
GlobalMapperDLLWrapper.GM_Projection_t aproj=new GM_Projection_t();
IntPtr LayerProjection;
IntPtr aLayer;
LastGMError = GlobalMapperDLL.GM_GetProjection(out LayerProjection);
aproj = (GlobalMapperDLLWrapper.GM_Projection_t)Marshal.PtrToStructure(LayerProjection, typeof(GlobalMapperDLLWrapper.GM_Projection_t));
LastGMError = GlobalMapperDLL.GM_CreateCustomVectorLayer(out aLayer, null, LayerProjection);
clsGlobalVARS.LayerHandles.Add(aLayer);
IntPtr theLayer = (IntPtr)clsGlobalVARS.LayerHandles[1];
LastGMError = GlobalMapperDLL.GM_AddPointToVectorLayer(theLayer, aPointFeature, 1);
after that code I receive an error InvalidParam.
Thanks in advance for your time.
Florian
Comments
-
Florian,
The GM_CreateCustomVector declaration for C# looks like:
// Creates a new custom layer for adding vector features to
[DllImport(DLLFileName, EntryPoint = "GM_CreateCustomVectorLayer")]
public static extern GM_LayerHandle_t32 GM_CreateCustomVectorLayer
(
string aDescription, // IN: Description to use for layer (can be NULL to use default)
ref GM_Projection_t aProj // IN: Native projection of new layer
);
So you would call it like:
aLayer = GlobalMapperDLL.GM_CreateCustomVectorLayer( "Layer Name Here", LayerProjection );
You should take a look at the C# sample application that you can download from the Developers page at http://www.globalmapper.com. The GlobalMapperDLLWrapper.cs file has recently been updated with a lot more declarations and the sample app itself has more sample code.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Many thanks Mike.
Florian -
Hello all,
I try to add a point to a custom layer, I add it but this point is going in 0,0 coordinate not when I want to 22.45, 45.62 Arc Degrees. I use this code:
IntPtr newLayer;
GlobalMapperDLLWrapper.GM_Projection_t geo = new GM_Projection_t();
geo.mProjSys = GlobalMapperDLLWrapper.PROJSYS.GM_PRJ_GEO;
geo.mDatum = GlobalMapperDLLWrapper.DATUM.GM_DATUM_WGS_84;
geo.mUnit = GlobalMapperDLLWrapper.UNIT.GM_PRJ_UNIT_ARC_DEGREES;
geo.mNumAttrs = 0;
m_geo = geo;
newLayer = (IntPtr)GlobalMapperDLL.GM_CreateCustomVectorLayer(NumeLayer, ref geo);
clsGlobalVARS.LayerHandles.Add(newLayer);
fixed (GM_Point_t* ptNou = &m_pt)
{
// Setup the point structure
GM_PointFeature_t thePoint = new GM_PointFeature_t();
thePoint.mFeatureInfo.mName = "Locatie contract";
thePoint.mFeatureInfo.mDesc = "Locatie";
thePoint.mPointStyle.mSymbolName = "DOT_CUSTOM_10_255_0_0";
thePoint.mPointStyle.mDrawLabel = 1;
thePoint.mPos = (IntPtr)ptNou;
// Add the point to the custom layer
LastGMError = GlobalMapperDLL.GM_AddPointToVectorLayer(newLayer, ref thePoint, 1);
GlobalMapperDLL.GM_SetLayerEnabled(newLayer, 1);
DrawLayersToBitmap();
Please let me know what I am doing wrong.
Many thanks,
Florian -
Florian,
For a single point feature you don't use the IntPtr as the mPos member of the GM_PointFeature_t stucture is just a GM_Point_t, not a pointer to it. So set it up as follows:
thePoint.mPos.mX = <longitude here>;
thePoint.mPos.mY = <latitude here>;
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Hi Mike,
Many thanks for your answer.
It's working the point is added but it is not red dot. It is just black small one.
I want to mention, I use the dll from 11.11.2009.
Thanks for your time.
Florian -
Florian,
Set the 3rd parameter for the GM_AddPointToVectorLayer call to 0 so that your specified style (i.e. symbol) will be used. By passing 1 you specify that the default style for the point type should be used rather than any symbol/font that you provided.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com
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