ThinkGeo.com    |     Documentation    |     Premium Support

Using projections with custom styles

I’m using a ScalingImageStyle for point represented by a bitmap that has a rotation as well. All my layers are unprojected WGS84, decimal degrees, and I’m projecting all the layers to a mercator projection like so:

Proj4Projection proj4Projection = new Proj4Projection();
proj4Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(3857);

I also put the MapUnit in meters since that’s what the projection requires.

I noticed when I’m using my custom style, the x and y values are getting messed up. For instance, I’ll set a point to my ScalingImageStyle, and make it’s long/lat -100,30, which should be somewhere in Texas. When I set a breakpoint and look at the values for x and y, it shows them as -0.00089831…, 0.00026945… I’m guessing this is the mercator projection points for the same long/lat I put in decimal degrees, so it plots it near 0, 0 on the map, instead of -100, 30.

I guess I’m confused how projections work and updating the features within the layers that are projected. When I add features to a projected layer and give those features long/lat values, will the values be in the unprojected form, and then reprojected? If I add a point to the map with a decimal degrees long/lat, how do I get that to appear at the right location on the map when it’s all projected in mercator (meters)?

Edit: Here’s an example -

I add a feature at -100, 30 (this is decimal degrees). When I look in the layer’s internal features, it shows that feature at {POINT(-0.000898315284119521 0.000269494585229815)}. And it plots it near 0,0 on the map, which makes sense since the layer is projected in mercator and the map is in meters. How do I get that to plot correctly at -100, 30?

Hi Dan_Weaver,

If you add the shape into the datasource, please follow its original projection.

For example, if your data is decimal degree, so you should want to add the point follow decimal degree, please ignore the reprojection it is assigned.

As below is a test code:

  winformsMap1.MapUnit = GeographyUnit.Meter;

        LayerOverlay layerOverlay = new LayerOverlay();

        Proj4Projection proj4Projection = new Proj4Projection();
        proj4Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
        proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(3857);
        proj4Projection.Open();

        InMemoryFeatureLayer layer = new InMemoryFeatureLayer();
        layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital1;
        layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        layer.FeatureSource.Projection = proj4Projection;
        layer.Open();

        PointShape point1 = new PointShape(-100, 30);
        layer.InternalFeatures.Add(new Feature(point1));

        PointShape point2 = new PointShape(0, 0);
        layer.InternalFeatures.Add(new Feature(point2));

        layerOverlay.Layers.Add(layer);
        winformsMap1.Overlays.Add(layerOverlay);
        winformsMap1.CurrentExtent = new RectangleShape(-20000000, 20000000, 20000000, -20000000);

        winformsMap1.Refresh();

You can see the current extent is big, and the -100,30 is not rendered near the 0,0.

Regards,

Ethan

Hmm, I’m still getting an issue when moving the feature. I’ll provide some code and screenshots below:

Here’s the code that’s adding the feature. You can see in the watch value below that it’s at -100, 30.


And here’s that feature on the map (this is just a pointshape with a label):

So that shows up correct. Now when I go to move the point to -101, 30, it moves it to 0,0. Below is the code for moving it:


As you can see, it shows the location of the feature now at -101, 31. But here’s how it’s displayed on the map:

Update: So it looks like if I deal with the InternalFeatures directly and not the EditTools, it works fine. Is this how it’s supposed to work? Thanks!

Update 2: Okay, it works with points, but not when moving vertices of lines/polygons or the whole shape. For instance, with a single point, I put in -100, 30, and the map projects it, which changes the -100, 30 to whatever that is in the new projection, but it is plotted at -100, 30 on the map as it should.

For lines and polygons though, when one vertex is changed, the others are already projected, but it thinks the projected vertices are decimal degrees as well, and projects it even further. Not sure how to deal with this issue.

Hi Dan,

Thanks for your screen shots and description, but I still confused about your question, could you please modify the sample to shows what’s the issue you still have so we can see how to solve it?

9065.zip (102.4 KB)

Regards,

Ethan

Sorry it was a confusing question. I solved it now. The problem stemmed from dealing with the FeatureSource instead of the InternalFeatures. Specifically, FeatureSource.GetFeatureById. This was returning the projected vertices, and when I went to update them, it would try projecting the vertices again, which were already in projected numbers. When getting the feature from InternalFeatures, it gave me the vertices in decimal degrees, which were then properly re-projected when updated.

Thanks!

Hi Dan,

Thanks for your update, I think your share should be helpful if somebody else met the same problem.

Regards,

Ethan