ThinkGeo.com    |     Documentation    |     Premium Support

ShapeFileFeatureLayer with points and projection

Hello,

I want to view a shape file with cities in it in a ShapeFileFeatureLayer. It works perfectly until I switch the coordinate reference system of the shapefile from web mercator (the destination system) to another system, let’s say WGS84. I add a ManagedProj4Projects to the ShapefileFeatureLayer.FeatureSource.Projection property, but no features are rendered. Should prjection work with point shape files?

Regards,
Markus

Hi Markus,

The projection works well for point shape file, I think that should because you hadn’t set correct projection.

Please double check something as below:

  1. You should set the projection like this:
    ManagedProj4Projection proj4 = new ManagedProj4Projection();
    proj4.InternalProjectionParametersString = ManagedProj4Projection.GetGoogleMapParametersString(); // epsg 3857
    proj4.ExternalProjectionParametersString = ManagedProj4Projection.GetDecimalDegreesParametersString(); // epsg 4326

  2. You need set the MapUnit equal GeographyUnit.DecimalDegree

  3. You need reset the current extent, you can convert that to 4326 by ManagedProj4Projection or you can directly assign to it if you know the 4326 bounding box of your points.

Regards,

Don

Hi Don,
thank you for your answer.
I need to project the other way round, from epsg:4326 (WGS 84) to epsg:3857 (WebMercator), because we will use GoogleMaps in a later stage and the data can possibly be in WGS 84.
MapUnit is set to GeographyUnit.Meter which is required for WebMercator.
CurrentExtent is set.
Here’s the shapefile I’m using:.DE_Cities_WGS84.zip (162.0 KB)
Regards,
Markus

Hi Markus,

This code as below works well with your data:

private void LoadMap()
    {
        string dataPath = @"D:\DE_Cities_WGS84.shp";
        Map1.MapUnit = GeographyUnit.Meter;
        ShapeFileFeatureLayer.BuildIndexFile(dataPath, BuildIndexMode.DoNotRebuild);
        ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(dataPath);
        layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
        layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        layer.Open();

        ManagedProj4Projection proj4 = new ManagedProj4Projection();
        proj4.ExternalProjectionParametersString = ManagedProj4Projection.GetGoogleMapParametersString(); // epsg 3857
        proj4.InternalProjectionParametersString = ManagedProj4Projection.GetDecimalDegreesParametersString(); // epsg 4326
        proj4.Open();

        layer.FeatureSource.Projection = proj4;

        LayerOverlay overlay = new LayerOverlay();
        overlay.Layers.Add(layer);
        Map1.Overlays.Add(overlay);

        Map1.CurrentExtent = layer.GetBoundingBox();
    }

Regards,

Don

Thank you, after comparing the source codes, it turned out that it was the silly mistake of mixing up internal and external projection attributes.

Hi Markus,

I am glad to hear that works.

Regards,

Don