1

I have a problem with saving STArea in sqlserver. Here is a query where I get the area of a polygon:

select Geometry::STGeomFromText('POLYGON ((51.3386535086000000 31.7951253522000000, 51.3388695102000000 31.7952389270000000, 51.3388979249000000 31.7952464707000000, 51.3390467037000000 31.7953440361000000, 51.3392599393000000 31.7954571079000000, 51.3394563273000000 31.7955843452000000, 51.3396358676000000 31.7956905439000000, 51.3398606703000000 31.7958423402000000, 51.3399567269000000 31.7958984151000000, 51.3402088545000000 31.7960463557000000, 51.3404525165000000 31.7961833999000000, 51.3405501656000000 31.7962423246000000, 51.3405803405000000 31.7962540593000000, 51.3407558575000000 31.7963579111000000, 51.3407710288000000 31.7963713221000000, 51.3408634812000000 31.7964024190000000, 51.3410357293000000 31.7965043429000000, 51.3411784731000000 31.7965789419000000, 51.3412407506000000 31.7965510301000000, 51.3414824009000000 31.7962486111000000, 51.3417441677000000 31.7959164362000000, 51.3419324253000000 31.7956736963000000, 51.3419411425000000 31.7956510652000000, 51.3417580817000000 31.7955185473000000, 51.3413181156000000 31.7952600494000000, 51.3409249205000000 31.7950360849000000, 51.3404942583000000 31.7947866395000000, 51.3400418032000000 31.7945303209000000, 51.3396468479000000 31.7942999862000000, 51.3395502046000000 31.7943521217000000, 51.3392463606000000 31.7945348471000000, 51.3389606215000000 31.7947612423000000, 51.3386898860000000 31.7950401921000000, 51.3386374991000000 31.7951089237000000, 51.3386374153000000 31.7951182276000000, 51.3386535086000000 31.7951253522000000))',32639).MakeValid().STArea()

It gives me 3.49106150461542E-06. How I can find that this area is right? In which unit is the STArea() measured in? And which code must I use instead 32639 for the points that came from the gps device?

**Edit,This is how I read points **

 var xmlDocument = XDocument.Load(xmlpath);

            XNamespace ns = xmlDocument.Root.GetDefaultNamespace();
            var values = xmlDocument.Root
                          .Descendants(ns + "trkpt")
                          .Select(x => new
                          {
                              lat = (string)x.Attribute("lat"),
                              lon = (string)x.Attribute("lon"),
                              ele = (string)x.Element(ns + "ele")

                          })
                          .ToList();
            //List<IPoint> ipoint = new List<IPoint>();
            string poinnts = "";
            foreach (var val in values)
            {
                string[] cordinates = { val.lat, val.lon, val.ele };

                poinnts += "," + val.lon.ToString() + " " + val.lat.ToString()+" " + val.ele.ToString();

            }
            poinnts=poinnts.Remove(0, 1);

            poinnts += ","+poinnts.Split(',')[0];

            GeomConverter gc = new GeomConverter();
            Polygon poly = gc.CreatePolygonFromPoints(poinnts);


            FeatureType res = poly.FeatureType;
            Fset = new DotSpatial.Data.FeatureSet(res);

            Fset.Projection = DotSpatial.Projections.ProjectionInfo.FromEpsgCode(Properties.Settings.Default.UTMCode);

            Fset.AddFeature(poly);
            area = poly.Area;
            length = poly.Length;
            this.status = true;

            return Fset;


        }

Here Is Create PolygonFromPoint()

    public Polygon CreatePolygonFromPoints(string feature)
    {


        string[] coordinates = feature.Split(',');


        double[] xy = new double[coordinates.Length*2];
        double[] z = new double[coordinates.Length];
        for (int i = 0; i < coordinates.Length; i++)
        {
            string[] cord = coordinates[i].Split(' ');
            double lon = double.Parse(cord[0]);
            double lat = double.Parse(cord[1]);
            double ele = double.Parse(cord[1]);

            xy[i*2] = lon;
            xy[i * 2 + 1] = lat;
            z[i] = ele;
        }

        ProjectionInfo pStart = KnownCoordinateSystems.Geographic.World.WGS1984;


        ProjectionInfo pEnd = KnownCoordinateSystems.Projected.UtmWgs1984.WGS1984UTMZone39N;


        Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, coordinates.Length);


        List<DotSpatial.Topology.Coordinate> co = new List<DotSpatial.Topology.Coordinate>();
        for (int i = 0; i < coordinates.Length; i++)
        {
            co.Add(new DotSpatial.Topology.Coordinate(xy[i*2],xy[i*2+1],z[i]));
        }

        Polygon polygon = new Polygon(co);
        return polygon;


    }

1 Answer 1

2

The area is certainly wrong because your data is in decimal degrees and the "geometry" data type treats it as though it were planar with units of equal distance. An "area" in degree units is meaningless. Degrees longitude cover shorter distances the farther you get from the equator.

For data in degrees you can use the "geography" data type which does geodetic computations for things such as distance or area and returns results in meters.

Most GPS devices use WGS 84 for which the code is 4326.

12
  • To be absolutely clear, "geometry" measurement functions return in whatever units the data are in. Commented Sep 9, 2014 at 16:10
  • Thanks for your help.you mean If I change my data type to geography it works fine?So the polygon that is created is wrong too?Can you give me an example how to work with this gps data? Commented Sep 9, 2014 at 18:14
  • If you change the datatype to geography, SRID 4326, your area and distance computations should be correct (in square meters/meters). Commented Sep 10, 2014 at 13:59
  • The polygon isn't wrong, it's simply that as a geometry it's treated as if the coordinate system is laid out on a flat surface rather than on a spheroid. If you were using a projected coordinate system to store your data, you'd need to use geometry because geography does not accept SRIDs that represent projections. Commented Sep 10, 2014 at 14:05
  • The other issue that sometimes gets people when first working with this type of data is that coordinates are x, y, that is longitude, latitude. If your polygon is in Iran you entered it correctly. If its in the Ukraine you got it backwards. Commented Sep 10, 2014 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.