kunluncat
kunluncat

Reputation: 21

Define polygon cross 180 meridian in DotSpatial

I am new to DotSpatial and I try to define a polygon cross 180 meridian by following:

FeatureSet fs = new FeatureSet(FeatureType.Polygon);
Coordinate[] coord = new Coordinate[5];
coord[0] = new Coordinate(30, 48);
coord[1] = new Coordinate(120, 45);
coord[2] = new Coordinate(-170, 64);
coord[3] = new Coordinate(30, 70);
coord[4] = new Coordinate(30, 48);
Polygon pg = new Polygon(coord);
 pg.Normalize();
fs.Features.Add(pg);
fs.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
fs.SaveAs(HttpContext.Current.Server.MapPath("~/shp/test2.shp"), true);

However, when I check the output shape file, the polygon edges intersects with each other

If I draw the same polygon in SQL Server with

DECLARE @Poly geography =   
  geography::STPolyFromText('POLYGON((30 48, 120 45, -170 64, 30 70, 30 48))', 4326)  
SELECT @Poly 

I can see the polygon shows correctly in "Spatial Results" in SQL Server Management Tools.

Can anyone help me how to solve this issue in DotSpatial.

Thank you very much!

Upvotes: 2

Views: 248

Answers (1)

Mapster
Mapster

Reputation: 88

Actually it is not an issue, it just follows the coordinates given based on order. If you change the order then it will be fine.

FeatureSet fs = new FeatureSet(FeatureType.Polygon);

Coordinate[] coord = new Coordinate[]
{
    new Coordinate(30, 48),               
    new Coordinate(-170, 64),
    new Coordinate(30, 70),
    new Coordinate(120, 45),
    new Coordinate(30, 48)
};

fs.AddFeature(new Polygon(new LinearRing(coord)));
fs.SaveAs(@"C:\Users\xxxx\Desktop\polygontest.shp", false);

and the output;

enter image description here

Upvotes: 0

Related Questions