There is a set of coordinates in the form of JSON from MapInfo. I used to use this in EzGIS to create polygons and a whole layer of geometry in the database. But in MapWinGIS everything is different. Can a small example of how this can be used? Here is a set of data… coordinate points and n-parts for the polygon.
{
All the same, anyone tell me example how to create a polygon? The examples in the documentation create circles and random. And I need a rectangle or a polygon at specific points.
// initialize a polygon shape
Shape shp = new Shape();
shp.Create(ShpfileType.SHP_POLYGON);
// iterate and add points
// loop through your points...
{
double lon, lat;
// set to values from your JSON file
shp.AddPoint(lon, lat);
}
// if it's not already, make sure last point is same as first point
shp.AddPoint(shp.Point[0].x, shp.Point[0].y);
// create a new shapefile (or you can open an existing)
Shapefile sf = new Shapefile();
sf.CreateNew("", ShpfileType.SHP_POLYGON);
if (sf.StartEditingShapes())
{
// add your polygons
sf.EditAddShape(shp);
}
sf.StopEditingShapes();
Thanks, I understand. And what should I do with the values of nparts [0,5] they are in MapInfo format. And also, if you make the deserialization of the polygon in MapWinGIS - it looks like this:
Nparts values appear if the object consists of two polygons, but they are combined. And when selected polygon, they are one whole. Nparts - I think it’s part of the polygon.
If you know where (at which point) each part starts, you would then call
shp.InsertPart(pointIndex, partIndex)
Presumably, the first part starts at the first point. This would be part 0 (zero).
In your sample data, it looks like maybe the 5th point down is the same point as the first point. Perhaps that’s the start of the second part. And perhaps that’s the interpretation of 0, 5. Point 0 is the start of the , first part, and point 5 is the start of the second part.
So, and I’m guessing a little, you would add your points, then call
shp.InsertPart(0, 0); // point zero is the start of part 0
shp.InsertPart(5, 1) // point 5 is the start of part 1