Hello all,
Can you think of any reason why this works:
var newShp = shp.Reproject(myGeoProjection, ref changedCount);
but this returns false and does not work:
shp.ReprojectInPlace(myGeoProjection, ref changedCount);
Are there any caveats when using ReprojectInPlace?
Regards,
Rob H
Hello Rob.
There are a few subtle differences internally.
By any chance was an error message available? something like shapefile.get_ErrorMsg(shapefile.LastErrorCode)
Hi Jerry,
Thanks for your message. That call returns “No Error” - however, “LastErrorCode” is actually set to 208.
Regards,
Rob
Thanks.
208 is “Shapefile function can not be executed in non-edit mode”. So I’m guessing that perhaps it’s a disk-based Shapefile, not an in-memory Shapefile, which I believe are always considered in edit mode.
This probably makes sense since it does indeed have to edit the shapes. Try wrapping it in StartEditingShapes/StopEditingShapes
, and see if that resolves it.
Regards.
Thanks Jerry, wrapping it in StartEditingShapes/StopEditingShapes has done the trick.
I do have a related, follow up question…
When I add an ascii grid layer, this triggers the same LayerProjectionIsEmptyEvent
event that I am using to reproject the shapefile in place and I can see the layer is coming through as a tif, which all makes sense - but is there a way I can do a similar reprojection of the image, or would I have to reproject the underlying ascii grid file before adding via AddLayer
Regards,
Rob
Hello Rob.
I don’t know too much about this; perhaps someone else has some insight. What I think you would want to look at is ‘warping’, although I don’t think you can warp on-the-fly like you can a vector layer. There’s a GDALWarp function in the Utilities class; I would probably start there.
Regards,
Jerry.