I'm using PostGIS 2.0.0 and would like to store a GML Surface in a way that allows calculating intersections between that surface and various points and lines. In my case, the Surface will have one PolygonPatch with no interior rings and an exterior ring which may be a LineStringSegment, a Geodesic, an Arc or a Circle. The distances can be in the order of tens to hundreds of miles. I see that PostGIS has CIRCULARSTRING and CURVEPOLYGON, which seem to be a good way of storing an Arc, except that they're not supported by the geography type, only geometry. What would be the best way to store this? (I'm quite new to PostGIS and GIS in general, so it's entirely possible I'm missing something obvious.)


2 Answers 2



You can store your GML features as a PostGIS Geometry datatype by using the ST_GeomFromGML function which will convert your GML to the geometry datatype. FYI: There are similar functions for KML, WKT, and so on.

just do something like:

INSERT into myTable (mygeomField) values (ST_GeomFromGML('
    <gml:LineString srsName="EPSG:4269">
            -71.16028,42.258729 -71.160837,42.259112 -71.161143,42.25932

Once you have it in the geometry field you can do all the fun intersects and stuff you want to do in PostGIS

Then you can spit your result back out in GML format using ST_AsGML

EDIT #1 I believe you're looking for:




I'm using "POSTGIS="1.5.2" (older version than you) and the following statement works just fine:

select ST_GeomFromText('CIRCULARSTRING(220268 150415,220227 150505,220227 150406)')

You have to use a combination of functions to get what you need.

distance_spheroid does not support CIRCULARSTRING because it takes in the geometry data types.

Please add an EDIT to your original question with a piece of sample GML you are having problems with and i will write out the statements for you.

  • Thanks, but importing from GML isn't really the core problem. The main question is around how to store the data in a way that allows accurate calculations. As I understand, the geometry type wouldn't work well for that, since it's based on a plane, and the geography type doesn't support curves.
    – EM0
    Nov 4, 2011 at 1:35
  • @EM: Check my EDIT#1
    – CaptDragon
    Nov 4, 2011 at 16:37
  • 1
    Thanks, tried those, but unfortunately they don't support CIRCULARSTRINGs.
    – EM0
    Nov 7, 2011 at 1:55
  • @EM: Check my EDIT #2
    – CaptDragon
    Nov 7, 2011 at 16:38
  • Yes, the statement to create a CIRCULARSTRING works, but distance calculations on that string use a plane, as I understand, because it's of type "geometry". Anyway, I'm going to try storing the data in two ways - the exact value as CIRCULARSTRING (geometry) and the approximated value (geography) generated using ST_CurveToLine.
    – EM0
    Nov 9, 2011 at 8:58

In the end I gave up on storing the "exact" arc or circle. When importing a GML Arc (which is defined by 3 points on the arc) I temporarily create a geometry CIRCULARSTRING, then convert it to geography, like this:

ST_RemoveRepeatedPoints(ST_CurveToLine(ST_GeomFromText('CIRCULARSTRING(...)', 4326)))::geography

When importing a GML ArcByCenterPoint (which is defined by the centre point, radius and start and end angles) I approximate it directly by projecting points at 1 degree intervals from the start angle to the end angle. This is done on a sphere, not spheroid, so it's not entirely accurate, but there are PostGIS tickets to implement azimuth and point projection for the geography type. Same for a circle.

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.