Create a DbGeography Polygon from a collection of DbGeography Points

entity-framework geospatial


Can somebody explain me how to create a collection of DbGeography objects of type "POINT" into a DbGeography object of type "Polygon"?

I currently have this, which generates the polygon, but I am missing the first step.

1. DbGeography multipoint = DbGeography.MultiPointFromText("MULTIPOINT(53.095124 -0.864716, 53.021255 -1.337128, 52.808019 -1.345367, 52.86153 -1.018524)", 4326)

2. DbGeometry temp_multipoint = DbGeometry.MultiPointFromBinary(multipoint.AsBinary(), 4326)

3. DbGeography polygon = DbGeography.PolygonFromBinary(temp_multipoint.ConvexHull.AsBinary(), 4326); (RESULT)

Creating the initial multipoint geography object from a list of DbGeography objects is the issue (POINTS)

3/1/2013 1:46:11 PM

Accepted Answer

A polygon can be created from numerous points without using WKT, as I later discovered. The following explanation is a little oversimplified, but

    var PolygonFromMultiplePoints = new DbGeography();

    using (var db = new LocationContext())
        //Select Locations known to be within a certain area which should define the polygon.
        foreach (var item in db.Locations)
    var temp_multipointgeometry = DbGeometry.MultiPointFromBinary(PolygonFromMultiplePoints.AsBinary(), DbGeometry.DefaultCoordinateSystemId);            
    PolygonFromMultiplePoints = DbGeography.PolygonFromBinary(temp_multipointgeometry.ConvexHull.AsBinary(), DbGeography.DefaultCoordinateSystemId);

The code sample presupposes that your database already has a collection of dbgeography points. Locations from GeoNames were imported to create the data in my database.

9/23/2013 11:39:37 PM

Popular Answer


Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow