Reprojection of a shapefile

What is the preferred method of reprojecting a shapefile?
I see that there is Shapefile.Reproject method and Utils.RerpojectShapefile.

The second one has an input for the shapefile’s source coordinate system. While the first one identifies is automatically from the .prj file (I assume?).

Which one of these two is the preferred one (more successful, stable, better tested)?

Hello @george

I don’t know that either is ‘better tested’, except to say that the Shapefile.Reproject is certainly used more than the other, since it is used internally anytime a layer requires reprojection.

There are a number of Utility functions that perform the same functions as are built in to the Shape or Shapefile classes. Another example is Shape.InterpolatePoint and Utils.LineInterpolatePoint. The utility functions might be used when you’re working ‘outside’ of the OCX, if that makes sense, while if you’re working within the OCX, and you have a Shape or Shapefile reference, you can just use the built-in function rather than calling the ‘external’ function.

You cannot necessarily assume that the current projection of the Shapefile is the same as that of the PRJ, since the Shapefile may have been reprojected when it got loaded into the map. So the Reproject of the Shapefile always takes it from ‘whatever it as at the moment’ to whatever projection you specify.

The strange thing about the Utility function, that I haven’t quite figured out, is that you provide both a ‘source’ and ‘target’ projection, which seems to ignore the ‘current’ projection of the Shapefile. It would seem to me that this could provide an unexpected result.

I would generally recommend using the Shapefile.Reproject. Keep in mind that there is also a ReprojectInPlace function, if you want to effectively assign the result right back into your source Shapefile.

Regards,
Jerry.

1 Like

Thank you @jerryfaust. I will do that.

Just one more question: When I use the Shapefile.Open, the Shapefile.GeoProjection property should be read from the .prj file? CRS information is not held in the .shp, .shx nor .dbf files?

Yes, when initially opening the file, it will use the .prj for the projection. Keep in mind, however, that if you have set GlobalSettings.ReprojectLayersOnAdding, then the layer may be reprojected once you add it to the map. The default value is False.

1 Like