This project has moved and is read-only. For the latest updates, please go here.

Coordinate System, projected or not, always need in lat/long

Topics: General Topics
Aug 14, 2006 at 7:58 PM

I want to know if it is possible to always work in lat/long regardless the projection, or coordinate system the .prj is actually on.

Its because all my system around sharpmap is based on lat/long coord. So when the user want to use a shapefile that has a projection and using a unit like meters, sharpmap return me all the coord in meters, so all my sytem stop working properly.

Is their a way in Sharpmap to not having to care about the .prj, and always make it work in lat/long? I don't want to change the projection on screen, just need to work in lat/long coordinate.

Aug 14, 2006 at 9:09 PM
I think i have found something:

I do the following:

ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(shape.CoordinateSystem, GeographicCoordinateSystem.WGS84);

"shape.CoordinateSystem" beign:

ShapeFile shape = layer.DataSource as ShapeFile;

The problem here, is that the factory always tell me: "Missing projection parameter "longitudeofcenter".
Aug 14, 2006 at 9:32 PM
Ok, i succeeded, but i think there is a problem with WKT parser, since i had to modify the .prj in order to make it works.

I use the last source code available.

First, i was missing those 2 parameters:


i had to manually add those parameters, and make them equals to 2 other parameters that was already in the .prj, wich are:


So it seems like SharpMap try to read latitudeofcenter and longitudeofcenter when LatitudeOfOrigin and Central_Meridian seems to be the two parameters to use.

I applied on my own the projection to the shapefile, using ArcMap 9.1.

I looked at different projection in ArcMap, and nonde seems to use those two parameters.
Aug 14, 2006 at 9:49 PM
I added this to the wkt parser for now:

ProjectionParameter longitudeofcenter = GetParameter("longitudeofcenter");
ProjectionParameter latitudeofcenter = GetParameter("latitudeofcenter");

if (longitudeofcenter == null)
longitudeofcenter = GetParameter("Central_Meridian");

if (latitudeofcenter == null)
latitudeofcenter = GetParameter("LatitudeOfOrigin");

So, if they are there, it use it, and if not, it use the one that i have identified. And then, if it's still null, it will throw the exception.
Aug 14, 2006 at 9:51 PM
That's not my day,

it's seems that "_ of _" on the forum apear of, anyway, there is an underscore surround the "of" above.
Aug 14, 2006 at 10:27 PM
Thanks for your report. Actually the .prj for ShapeFiles isn't fully compliant WKT, and this is probably the cause. I haven't been able to find a specification of the .prj format, and there the differences are, but from what I've seen, it's more or less 99% WKT.
I'll add an option checking whether the other parameters are present in case of a missing parameter. Until then your work-around should be fine too.
Aug 14, 2006 at 10:27 PM
This discussion has been copied to Work Item 2097. You may wish to continue further discussion there.
Aug 14, 2006 at 10:39 PM
I just notive that by applying this transformation, it cancel the projection i had in that shapefile.

So my question is still valid:

Is there a way to work in lat/long and keep the projection of the shapefile.
Aug 14, 2006 at 10:40 PM
Sorry, wrong topic...
Aug 14, 2006 at 10:41 PM
Thanks for your reply and informations.
Aug 14, 2006 at 10:41 PM
Ups, perhaps I was a bit too quick there. There seems to be a problem with the Albers projection which expects the wrong parameters, but all other projections use the parameters you describe.

Was this the projection you were experiencing problems with?
Aug 14, 2006 at 10:47 PM
Not really, i have fall on that error, while trying to work in lat/long even for shapefile projected.

But, i think i have found a solution for my problem. I'll create a Transformation, but i won't apply it to the layer. So the layer will still be projected.

And then, i'll use that transformation, to convert all the point from the layer, the same with MapToWorld and WorldToMap fonction. So basicaly, it will make my system believe that it's working in lat/long, even if the shape is not.

Sounds logical to you? :)