ThinkGeo.com    |     Documentation    |     Premium Support

Xamarin Forms - Projections

Hello,

I am currently using a map view for offline files (Tiff & shape), and I want to work with the projection of this files, not to set it programatically.
How can I get that file’s projection? or how can I get the projection of the map after adding layers for that files?

I tried to get the projection of the layers but it returns null

Projection proj = myShapeFileFeatureLayer.FeatureSource.Projection;

I need it because I want to add a PointShape to the map view, with its current projection.

Thanks.

Hi Carlos,

Shape or Tiff file doesn’t contains projection information internal, and projection information is stored in a “.prj” file. So before setting projection of ShapeFileFeatureLayer, you can’t get projection from ShapeFileFeatureLayer.

How do you want to add a PointShape to the map view? If you want to do that by clicking on screen, you don’t need to get the layer projection. You have two ways as below:

  1. Use TrackInteractiveOverlay to implement that, please refer to the sample (http://wiki.thinkgeo.com/wiki/map_suite_android_drawing_editing).

  2. Capture screen point that you clicked on screen. then convert the screen point to world vertex by calling ExtentHelper. ToWorldCoordinate() function. And at last add the world vertex to your InMemoryFeatureLayer.

Thanks,

I want to add the point from the given GPS location (WGS84), but it does not match with the one taken by default when I add a tiff or shape file.

Hi Carlos,

We get your requirements, the following points are about your questions:

  • Shape file doesn’t contain the projection information.
    If you don’t want to hardcode projection of ShapeFileFeatureLayer, you should want to create a ‘.prj’ file for your shape file, then initialize ManagedProj4Projection object, then assign projection information which is read from the ‘.prj’ file. You can download MapSuiteGISEditor from ProductCenter and build the ‘.prj’ file by this utility.

    Please refer to the following code:

    ManagedProj4Projection prj = new ManagedProj4Projection();
    prj.InternalProjectionParametersString = ManagedProj4Projection.ConvertPrjToProj4(File.ReadAllText(“Projection File Path”));
    prj.ExternalProjectionParametersString = ManagedProj4Projection.GetWgs84ParametersString();
    prj.Open();
    layer.FeatureSource.Projection = prj;

  • At the present, we don’t support reprojection for tiff file on MapsuiteFormsEdition.

Hope it is helpful for you.

Thanks,
Bill

Hi Bill,

this was very helpful, it works great now.

Thanks for your help.
Carlos.

Hi Carlos,

I am glad to hear that’s helpful.

Any question please let us know.

Regards,
Bill