問題 EllipseGeography

  • Thursday, May 06, 2010 9:39 PM
     
     

    I am creating an SqlGeography from an EllipseGeometry using GetFlattenedPathGeometry() and getting the points from the figure segments and converting those points to lat/lon.  This works fine, but I cannot figure out how to know that the resulting SqlGeography represents an ellipse so that I can reconstruct the EllipseGeometry.  Any suggestions?

All Replies

  • Friday, May 07, 2010 11:50 AM
    Answerer
     
     

    SQL Server doesn't recognise shapes such as ellipses or circles - it only operates with points, linestrings, or polygons (or combinations of these primitives).

    So, the only way of storing an 'ellipse' is to have a many-sided polygon, where the straight lines connecting each point in the exterior ring of the polygon approximate the 'true' curved edge of the ellipse.


    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
  • Friday, May 07, 2010 3:40 PM
     
     

    Thank you for responding.  

    As you say "the only way of storing an 'ellipse' is to have a many-sided polygon" which is what I am doing.  However, when I retrieve that geography from my db I am looking for a way to test to see if it is in the shape of an ellipse so that I may create an EllipseGeometry (Wpf) to represent it.  Any help would be greatly appreciated

  • Friday, May 07, 2010 4:52 PM
    Answerer
     
     

    So you want to test an arbitrary n-sided polygon to test whether it "looks like" an ellipse, within a given margin of error? That sounds very subjective to me - a square approximates an ellipse, if you tolerate enough margin of error... i guess it would be programmatically possible to devise such a test, but very hard mathematically.

    Or, do you know that these shapes are meant to represent ellipses at the point of creation? if so, you simply store an additional column of metadata in the DB (i.e. a column called IsEllipse that is populated with either 'Y' or 'N' with each geometry)


    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
  • Tuesday, May 11, 2010 12:02 PM
     
     

    You are correct in pointing out that there is no concrete way to determine that an n-sided polygon is an ellipse.  However, I am having luck in testing for the possibility by doing the following. 

    I Create an SqlGeometry from the WKB of the SqlGeography and use the distance from the centroid to the startpoint as a radiusX.

    I take the area of the shape / radiusX / PI to get a radiusY. Then I calculate the ration of radiusX to radiusY

    After converting the lat/lon points of the centroid and startpoint to pixel points on my map, I create an ellipse given the distance from the centroid to the startpoint (in pixels) as my radiusX(pixel) with the radiusY(pixel) being of the same ratio of the I calcuated above.

    I use that ellipse to create an SqlGeography and compare the area of the new SqlGeography to the original and if they are within a small tolerance assume it to be an ellipse.

    Although it is really fuzzy lotgic, it seems to be working so far.

    Thank you for your responses, if anyone can conceive of a less fuzzy solution I would love to hear it.

  • Tuesday, October 05, 2010 5:19 PM
     
     

    tanoshimi, can shape files ever contain ellipse, arc band, in other words types that sql does not support?

    I have to deal with queries that can be an ellipse or arcband(class descriptions below). What is the best way to build these guys to pass to sql as geography parameters, or represent as text so I can call STGeomFromText? I gather from this thread there is no way to determine whether the sql geogrphy columns are storing one of those types by using STAsText.

    public class Polygon : Geo
     {
      public PolygonExetrior Exterior { get; set; }
     }

     public class PolygonExetrior
     {
      private PolygonLinearRing LinearRing { get; set; }
     }
     public class PolygonLinearRing
     {
      private List<Point> Points { get; set; }
     }


    public class Circle : Geo
     {
      private Point Point { get; set; }
      private double Radius { get; set; }
     }
     public class Ellipse : Geo
     {
      private Point Point { get; set; }
      private double MajorAxis { get; set; }
      private double MinorAxis { get; set; }
      private double Orientation { get; set; }
     }
     public class GeoArcBand : Geo
     {
      private Point Point { get; set; }
      private double InnerRadius { get; set; }
      private double OuterRadius { get; set; }
      private double StartAngle { get; set; }
      private double OpeningAngle { get; set; }
     } 

  • Wednesday, October 06, 2010 6:15 AM
     
     

    Hi MHabbib and Scot,

     

    You have the option to use the M parameter (it's used to store any value for each point). So,

     

    - Having the segments that "approximate" the figure, create a sqlgeography

    - In the first point, store the "type":

    - 1 ellipse

    -2  circle

    ...

    - null: No defined figure

    - Use the next points to store the parameters need to create again the figure:

    - For ellipse: center (point 2), radiusX (point 3), radiusY (point 4)

    - etc

     

    Of course you can store this information in other columns of the table. If you are going to do it this way, just rember that if you operate the geography M values will be losted.