This project is read-only.

Read fields, values and feature points from a .shp example

Jan 19, 2016 at 10:02 PM
I was wondering if somebody could provide a MapWindow C# example on how .shp files' fields, values and feature points can be read from it, and printed to a console?
There are C# MapWindow examples, but none of them contains this kind of example.

Thank you for the help in advance.
Jan 21, 2016 at 1:48 PM
You were at the right location when you looked in the API documentation.
Going to the specific function will also reveil some more info.
A shapefile has shapes and fields. A field has columns and a shape has points.

Here's some info about the field class:
Using NumShapes you can loop through all shapes in a shapefile:
With NumPoints you can loop through all points in a shape:

Some pseudocode:
-- Open shapefile
-- Loop through shapes:
for (int i=0; i<Shapefile.NumShapes; i++)
  shp = Shapefile.get_Shape(i) 
  -- Loop through points:
  for (int j = 0; shp.NumPoints; j++)
    pnt = shp.get_Point(j);
-- Loop through fields:
for (int i=0; i<Shapefile.NumFields; i++)
  fld = Shapefile.get_Field(i);
When you also want the value of the shape you can use
Shapefile.get_CellValue (int FieldIndex, int ShapeIndex)
Jan 21, 2016 at 2:12 PM
Thank you Mr. Meems,
How would the transformation of the .shp geometry be done (transformation to some EPSG projection for example)?
Can it be done by transforming the entire .shp file, or it needs to be done by transforming each individual point?
Jan 21, 2016 at 2:58 PM
Jan 21, 2016 at 4:56 PM
Edited Jan 21, 2016 at 4:57 PM
Thank you.

I replicated the upper code to ironpython. However an error emerges on shape file Open method.
I am wondering if sometimes this happens in C# too?

When I call the following ironpython cide:
shpFilePath = "D:/mapwindow/nyad.shp"
shapeFile = MapWinGIS.ShapefileClass()
On line 3, an error emerges:
Could not convert argument 0 for call to Open.
Any advice on why is this happening?

I apologize for asking such question not related with C#.
Jan 22, 2016 at 9:21 AM
Are you sure you need the ShapefileClass and not just MapWinGIS.Shapefile:

Here's an example how to use
You need to pass 'null' as the second argument.


Jan 22, 2016 at 11:25 AM
Edited Jan 22, 2016 at 11:26 AM
Thank you.

When I load the Interop.MapWinGIS.dll file to ironpython, there's no Open function within MapWinGIS.Shapefile. There is only one within MapWinGIS.ShapefileClass.

I tried supplying the "null" as the second argument also ("None" in ironpython):
shpFilePath = "D:/mapwindow/nyad.shp"
shapeFile = MapWinGIS.ShapefileClass()
shapeFile.Open(shpFilePath, None)
But the same error message appears:
Could not convert argument 0 for call to Open.
I also tried found an example of passing an instance of MapWinGIS.ShapefileClass.GlobalCallback as the second argument to MapWinGIS.ShapefileClass().Open function, but did not succeed in replicating it to the ironpython.
Jan 25, 2016 at 7:53 AM
We're almost ready to release a new version of MapWinGIS. This installer will include the interop dlls.
Hopefully you can wait a few more days.