Geometry InputThese functions create geometry objects from various textual or binary formats.Well-Known Text (WKT)ST_BdPolyFromTextConstruct a Polygon given an arbitrary collection of closed
linestrings as a MultiLineString Well-Known text representation.geometry ST_BdPolyFromTexttext WKTinteger sridDescriptionConstruct a Polygon given an arbitrary collection of closed
linestrings as a MultiLineString Well-Known text representation.Throws an error if WKT is not a MULTILINESTRING. Throws an
error if output is a MULTIPOLYGON; use ST_BdMPolyFromText in that case, or
see ST_BuildArea() for a
postgis-specific approach.&sfs_compliant; s3.2.6.2Performed by the GEOS module.Availability: 1.1.0ExamplesForthcoming
-->
See Also, ST_BdMPolyFromTextConstruct a MultiPolygon given an arbitrary collection of
closed linestrings as a MultiLineString text
representation Well-Known text representation.geometry ST_BdMPolyFromTexttext WKTinteger sridDescriptionConstruct a Polygon given an arbitrary collection of closed
linestrings, polygons, MultiLineStrings as Well-Known text representation.Throws an error if WKT is not a MULTILINESTRING. Forces
MULTIPOLYGON output even when result is really only composed by a
single POLYGON; use ST_BdPolyFromText if you're sure a
single POLYGON will result from operation, or see ST_BuildArea() for a postgis-specific
approach.&sfs_compliant; s3.2.6.2Performed by the GEOS module.Availability: 1.1.0See Also, ST_GeogFromTextReturn a specified geography value from Well-Known Text representation or extended (WKT). geography ST_GeogFromTexttext EWKTDescriptionReturns a geography object from the well-known text or extended well-known representation. SRID 4326 is assumed if unspecified.
This is an alias for ST_GeographyFromText. Points are always expressed in long lat form.ExamplesAdd a WGS 84 geography point column to a table.ALTER TABLE sometable ADD COLUMN geog geography(POINT, 4326);Populate the geography column from longitude and latitude columns.UPDATE sometable
SET geog = ST_GeogFromText('SRID=4326;POINT(' || lon || ' ' || lat || ')');Specify a geography point using EPSG:4267, NAD27.SELECT ST_GeogFromText('SRID=4267;POINT(-77.0092 38.889588)');SRID=4267;POINT(-77.0092 38.889588)See Also, ST_GeographyFromTextReturn a specified geography value from Well-Known Text representation or extended (WKT). geography ST_GeographyFromTexttext EWKTDescriptionReturns a geography object from the well-known text representation. SRID 4326 is assumed if unspecified.See Also, ST_GeomCollFromTextMakes a collection Geometry from collection WKT with the given SRID. If SRID is
not given, it defaults to 0.geometry ST_GeomCollFromTexttext WKTinteger sridgeometry ST_GeomCollFromTexttext WKTDescriptionMakes a collection Geometry from the Well-Known-Text (WKT) representation with the given SRID. If SRID is
not given, it defaults to 0.OGC SPEC 3.2.6.2 - option SRID is from the conformance suiteReturns null if the WKT is not a GEOMETRYCOLLECTIONIf you are absolutely sure all your WKT geometries are collections, don't use this function.
It is slower than ST_GeomFromText since it adds an additional validation step.
&sfs_compliant; s3.2.6.2&sqlmm_compliant;ExamplesSELECT ST_GeomCollFromText('GEOMETRYCOLLECTION(POINT(1 2), LINESTRING(1 2,3 4))');See Also, ST_GeomFromEWKTReturn a specified ST_Geometry value from Extended Well-Known Text representation (EWKT).geometry ST_GeomFromEWKTtext EWKTDescriptionConstructs a PostGIS ST_Geometry object from the OGC Extended Well-Known text (EWKT) representation.The EWKT format is not an OGC standard, but an PostGIS specific format that includes the spatial reference system (SRID)
identifierEnhanced: 2.0.0 support for Polyhedral surfaces and TIN was introduced.&Z_support;&curve_support;&P_support;&T_support;ExamplesCreate a LineString with SRID 4269.SELECT ST_GeometryType(geom) AS geometry_type, ST_SRID(geom) AS srid
FROM ST_GeomFromEWKT('SRID=4269;LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932)') AS geom; geometry_type | srid
---------------+------
ST_LineString | 4269
(1 row)Create a MultiLineString with SRID 4269.SELECT ST_GeometryType(geom) AS geometry_type, ST_SRID(geom) AS srid
FROM ST_GeomFromEWKT('SRID=4269;MULTILINESTRING((-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932))') AS geom; geometry_type | srid
---------------------+------
ST_MultiLineString | 4269
(1 row)Create a Point with SRID 4269.SELECT ST_GeometryType(geom) AS geometry_type, ST_SRID(geom) AS srid
FROM ST_GeomFromEWKT('SRID=4269;POINT(-71.064544 42.28787)') AS geom; geometry_type | srid
---------------+------
ST_Point | 4269
(1 row)Create a Polygon with SRID 4269.SELECT ST_GeometryType(geom) AS geometry_type, ST_SRID(geom) AS srid
FROM ST_GeomFromEWKT('SRID=4269;POLYGON((-71.1776585052917 42.3902909739571,-71.1776820268866 42.3903701743239,
-71.1776063012595 42.3903825660754,-71.1775826583081 42.3903033653531,-71.1776585052917 42.3902909739571))') AS geom; geometry_type | srid
---------------+------
ST_Polygon | 4269
(1 row)Create a MultiPolygon with SRID 4269.SELECT ST_GeometryType(geom) AS geometry_type, ST_SRID(geom) AS srid
FROM ST_GeomFromEWKT('SRID=4269;MULTIPOLYGON(((-71.1031880899493 42.3152774590236,
-71.1031627617667 42.3152960829043,-71.102923838298 42.3149156848307,
-71.1023097974109 42.3151969047397,-71.1019285062273 42.3147384934248,
-71.102505233663 42.3144722937587,-71.10277487471 42.3141658254797,
-71.103113945163 42.3142739188902,-71.10324876416 42.31402489987,
-71.1033002961013 42.3140393340215,-71.1033488797549 42.3139495090772,
-71.103396240451 42.3138632439557,-71.1041521907712 42.3141153348029,
-71.1041411411543 42.3141545014533,-71.1041287795912 42.3142114839058,
-71.1041188134329 42.3142693656241,-71.1041112482575 42.3143272556118,
-71.1041072845732 42.3143851580048,-71.1041057218871 42.3144430686681,
-71.1041065602059 42.3145009876017,-71.1041097995362 42.3145589148055,
-71.1041166403905 42.3146168544148,-71.1041258822717 42.3146748022936,
-71.1041375307579 42.3147318674446,-71.1041492906949 42.3147711126569,
-71.1041598612795 42.314808571739,-71.1042515013869 42.3151287620809,
-71.1041173835118 42.3150739481917,-71.1040809891419 42.3151344119048,
-71.1040438678912 42.3151191367447,-71.1040194562988 42.3151832057859,
-71.1038734225584 42.3151140942995,-71.1038446938243 42.3151006300338,
-71.1038315271889 42.315094347535,-71.1037393329282 42.315054824985,
-71.1035447555574 42.3152608696313,-71.1033436658644 42.3151648370544,
-71.1032580383161 42.3152269126061,-71.103223066939 42.3152517403219,
-71.1031880899493 42.3152774590236)),
((-71.1043632495873 42.315113108546,-71.1043583974082 42.3151211109857,
-71.1043443253471 42.3150676015829,-71.1043850704575 42.3150793250568,-71.1043632495873 42.315113108546)))') AS geom; geometry_type | srid
-------------------+------
ST_MultiPolygon | 4269
(1 row)Create a 3D CircularString without an SRID.SELECT ST_GeometryType(geom) AS geometry_type, ST_SRID(geom) AS srid
FROM ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)') AS geom; geometry_type | srid
--------------------+------
ST_CircularString | 0
(1 row)Create a PolyhedralSurface without an SRID.SELECT ST_GeometryType(geom) AS geometry_type, ST_SRID(geom) AS srid
FROM ST_GeomFromEWKT('POLYHEDRALSURFACE(
((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),
((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),
((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),
((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),
((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),
((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1))
)') AS geom; geometry_type | srid
--------------------------+------
ST_PolyhedralSurface | 0
(1 row)See Also, ST_GeomFromMARC21Takes MARC21/XML geographic data as input and returns a PostGIS geometry object.
geometry
ST_GeomFromMARC21text marcxmlDescription
This function creates a PostGIS geometry from a MARC21/XML record, which can contain a POINT or a POLYGON.
In case of multiple geographic data entries in the same MARC21/XML record, a MULTIPOINT or MULTIPOLYGON will be returned.
If the record contains mixed geometry types, a GEOMETRYCOLLECTION will be returned.
It returns NULL if the MARC21/XML record does not contain any geographic data (datafield:034).
LOC MARC21/XML versions supported:
MARC21/XML 1.1Availability: 3.3.0, requires libxml2 2.6+
The MARC21/XML Coded Cartographic Mathematical Data currently does not provide any means to describe the Spatial Reference System of the encoded coordinates, so
this function will always return a geometry with SRID 0.
Returned POLYGON geometries will always be clockwise oriented.
ExamplesConverting MARC21/XML geographic data containing a single POINT encoded as hddd.dddddd00000nz a2200000nc 4500040277569W004.500000W004.500000N054.250000N054.250000
'
);
]]>POINT(-4.5 54.25)Converting MARC21/XML geographic data containing a single POLYGON encoded as hdddmmss01062cem a2200241 a 4500 84696781 a50000E0130600E0133100N0523900N0522300
'
);
]]>POLYGON((13.1 52.65,13.516666666666667 52.65,13.516666666666667 52.38333333333333,13.1 52.38333333333333,13.1 52.65))Converting MARC21/XML geographic data containing a POLYGON and a POINT:a50000E0130600E0133100N0523900N0522300W004.500000W004.500000N054.250000N054.250000
'
);
]]>GEOMETRYCOLLECTION(POLYGON((13.1 52.65,13.516666666666667 52.65,13.516666666666667 52.38333333333333,13.1 52.38333333333333,13.1 52.65)), POINT(-4.5 54.25))See AlsoST_GeometryFromTextReturns a geometry from Well-Known Text (WKT). Alias for ST_GeomFromText.geometry ST_GeometryFromTexttext WKTgeometry ST_GeometryFromTexttext WKTinteger sridDescriptionThis function is an alias for and provides the same signatures.Availability: 1.2.2&sfs_compliant;&sqlmm_compliant; SQL-MM 3: 5.1.40See AlsoST_GeomFromTextReturn a specified ST_Geometry value from Well-Known Text representation (WKT).geometry ST_GeomFromTexttext WKTgeometry ST_GeomFromTexttext WKTinteger sridDescriptionConstructs a PostGIS ST_Geometry object from the OGC Well-Known text representation.There are two variants of ST_GeomFromText function. The first takes no SRID and returns a geometry
with no defined spatial reference system (SRID=0). The second takes a SRID as the second argument
and returns a geometry that includes this SRID as part of its metadata.
&sfs_compliant; s3.2.6.2 - option SRID is from the conformance suite.&sqlmm_compliant; SQL-MM 3: 5.1.40&curve_support;While not OGC-compliant, is faster than ST_GeomFromText and ST_PointFromText. It is also easier to use for numeric coordinate values. is another option similar in speed to and is OGC-compliant, but doesn't support anything but 2D points.Changed: 2.0.0 In prior versions of PostGIS ST_GeomFromText('GEOMETRYCOLLECTION(EMPTY)') was allowed. This is now illegal in PostGIS 2.0.0 to better conform with SQL/MM standards. This should now be
written as ST_GeomFromText('GEOMETRYCOLLECTION EMPTY')ExamplesCreate a LineString with SRID 0.SELECT ST_SRID(ST_GeomFromText('LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932)'));0Create the same LineString with SRID 4269.SELECT ST_SRID(ST_GeomFromText('LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932)', 4269));4269Create a MultiLineString.SELECT ST_GeometryType(ST_GeomFromText('MULTILINESTRING((-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932))'));ST_MultiLineStringCreate a Point.SELECT ST_GeometryType(ST_GeomFromText('POINT(-71.064544 42.28787)'));ST_PointCreate a Polygon.SELECT ST_GeometryType(ST_GeomFromText('POLYGON((-71.1776585052917 42.3902909739571,-71.1776820268866 42.3903701743239,
-71.1776063012595 42.3903825660754,-71.1775826583081 42.3903033653531,-71.1776585052917 42.3902909739571))'));ST_PolygonCreate a MultiPolygon with SRID 4326.SELECT ST_GeometryType(ST_GeomFromText('MULTIPOLYGON(((-71.1031880899493 42.3152774590236,
-71.1031627617667 42.3152960829043,-71.102923838298 42.3149156848307,
-71.1023097974109 42.3151969047397,-71.1019285062273 42.3147384934248,
-71.102505233663 42.3144722937587,-71.10277487471 42.3141658254797,
-71.103113945163 42.3142739188902,-71.10324876416 42.31402489987,
-71.1033002961013 42.3140393340215,-71.1033488797549 42.3139495090772,
-71.103396240451 42.3138632439557,-71.1041521907712 42.3141153348029,
-71.1041411411543 42.3141545014533,-71.1041287795912 42.3142114839058,
-71.1041188134329 42.3142693656241,-71.1041112482575 42.3143272556118,
-71.1041072845732 42.3143851580048,-71.1041057218871 42.3144430686681,
-71.1041065602059 42.3145009876017,-71.1041097995362 42.3145589148055,
-71.1041166403905 42.3146168544148,-71.1041258822717 42.3146748022936,
-71.1041375307579 42.3147318674446,-71.1041492906949 42.3147711126569,
-71.1041598612795 42.314808571739,-71.1042515013869 42.3151287620809,
-71.1041173835118 42.3150739481917,-71.1040809891419 42.3151344119048,
-71.1040438678912 42.3151191367447,-71.1040194562988 42.3151832057859,
-71.1038734225584 42.3151140942995,-71.1038446938243 42.3151006300338,
-71.1038315271889 42.315094347535,-71.1037393329282 42.315054824985,
-71.1035447555574 42.3152608696313,-71.1033436658644 42.3151648370544,
-71.1032580383161 42.3152269126061,-71.103223066939 42.3152517403219,
-71.1031880899493 42.3152774590236)),
((-71.1043632495873 42.315113108546,-71.1043583974082 42.3151211109857,
-71.1043443253471 42.3150676015829,-71.1043850704575 42.3150793250568,-71.1043632495873 42.315113108546)))', 4326));ST_MultiPolygonCreate a CircularString.SELECT ST_GeometryType(ST_GeomFromText('CIRCULARSTRING(220268 150415,220227 150505,220227 150406)'));ST_CircularStringSee Also, , ST_LineFromTextMakes a Geometry from WKT representation with the given SRID. If SRID is
not given, it defaults to 0.geometry ST_LineFromTexttext WKTgeometry ST_LineFromTexttext WKTinteger sridDescriptionMakes a Geometry from WKT with the given SRID. If SRID is
not given, it defaults to 0. If WKT passed in is not a LINESTRING, then null is returned. OGC SPEC 3.2.6.2 - optional SRID is from the conformance
suite.If you know all your geometries are LINESTRINGS, its more efficient to just use ST_GeomFromText.
This just calls ST_GeomFromText and adds additional validation that it returns a linestring.&sfs_compliant; s3.2.6.2&sqlmm_compliant; SQL-MM 3: 7.2.8ExamplesSELECT ST_LineFromText('LINESTRING(1 2,3 4)') AS aline,
ST_LineFromText('POINT(1 2)') IS NULL AS null_return;
aline | null_return
------------------------------------
LINESTRING(1 2,3 4) | t
See AlsoST_MLineFromTextReturn a specified ST_MultiLineString value from WKT representation.geometry ST_MLineFromTexttext WKTinteger sridgeometry ST_MLineFromTexttext WKTDescriptionMakes a Geometry from Well-Known-Text (WKT) with the given SRID. If SRID is
not given, it defaults to 0.OGC SPEC 3.2.6.2 - option SRID is from the conformance
suiteReturns null if the WKT is not a MULTILINESTRINGIf you are absolutely sure all your WKT geometries are points, don't use this function.
It is slower than ST_GeomFromText since it adds an additional validation step.
&sfs_compliant; s3.2.6.2&sqlmm_compliant;SQL-MM 3: 9.4.4ExamplesSELECT ST_MLineFromText('MULTILINESTRING((1 2,3 4),(4 5,6 7))');See AlsoST_MPointFromTextMakes a Geometry from WKT with the given SRID. If SRID is
not given, it defaults to 0.geometry ST_MPointFromTexttext WKTinteger sridgeometry ST_MPointFromTexttext WKTDescriptionMakes a Geometry from WKT with the given SRID. If SRID is
not given, it defaults to 0.OGC SPEC 3.2.6.2 - option SRID is from the conformance
suiteReturns null if the WKT is not a MULTIPOINTIf you are absolutely sure all your WKT geometries are points, don't use this function.
It is slower than ST_GeomFromText since it adds an additional validation step.
&sfs_compliant; 3.2.6.2&sqlmm_compliant; SQL-MM 3: 9.2.4ExamplesSELECT ST_MPointFromText('MULTIPOINT((1 2),(3 4))');
SELECT ST_MPointFromText('MULTIPOINT((-70.9590 42.1180),(-70.9611 42.1223))', 4326);See AlsoST_MPolyFromTextMakes a MultiPolygon Geometry from WKT with the given SRID. If SRID is
not given, it defaults to 0.geometry ST_MPolyFromTexttext WKTinteger sridgeometry ST_MPolyFromTexttext WKTDescriptionMakes a MultiPolygon from WKT with the given SRID. If SRID is
not given, it defaults to 0.OGC SPEC 3.2.6.2 - option SRID is from the conformance suiteThrows an error if the WKT is not a MULTIPOLYGONIf you are absolutely sure all your WKT geometries are multipolygons, don't use this function.
It is slower than ST_GeomFromText since it adds an additional validation step.
&sfs_compliant; s3.2.6.2&sqlmm_compliant; SQL-MM 3: 9.6.4ExamplesCreate a 3D MultiPolygon with an interior ring and SRID 0.SELECT ST_MPolyFromText(
'MULTIPOLYGON(((0 0 1,20 0 1,20 20 1,0 20 1,0 0 1),
(5 5 3,5 7 3,7 7 3,7 5 3,5 5 3)))'
);MULTIPOLYGON(((0 0 1,20 0 1,20 20 1,0 20 1,0 0 1),(5 5 3,5 7 3,7 7 3,7 5 3,5 5 3)))Create a MultiPolygon with SRID 4326.SELECT ST_MPolyFromText(
'MULTIPOLYGON(((-70.916 42.1002,-70.9468 42.0946,-70.9765 42.0872,
-70.9754 42.0875,-70.9749 42.0879,-70.9752 42.0881,-70.9754 42.0891,
-70.9758 42.0894,-70.9759 42.0897,-70.9759 42.0899,-70.9754 42.0902,
-70.9756 42.0906,-70.9753 42.0907,-70.9753 42.0917,-70.9757 42.0924,
-70.9755 42.0928,-70.9755 42.0942,-70.9751 42.0948,-70.9755 42.0953,
-70.9751 42.0958,-70.9751 42.0962,-70.9759 42.0983,-70.9767 42.0987,
-70.9768 42.0991,-70.9771 42.0997,-70.9771 42.1003,-70.9768 42.1005,
-70.977 42.1011,-70.9766 42.1019,-70.9768 42.1026,-70.9769 42.1033,
-70.9775 42.1042,-70.9773 42.1043,-70.9776 42.1043,-70.9778 42.1048,
-70.9773 42.1058,-70.9774 42.1061,-70.9779 42.1065,-70.9782 42.1078,
-70.9788 42.1085,-70.9798 42.1087,-70.9806 42.109,-70.9807 42.1093,
-70.9806 42.1099,-70.9809 42.1109,-70.9808 42.1112,-70.9798 42.1116,
-70.9792 42.1127,-70.979 42.1129,-70.9787 42.1134,-70.979 42.1139,
-70.9791 42.1141,-70.9987 42.1116,-71.0022 42.1273,-70.9408 42.1513,
-70.9315 42.1165,-70.916 42.1002)))',
4326
);SRID=4326;MULTIPOLYGON(((-70.916 42.1002,-70.9468 42.0946,-70.9765 42.0872,-70.9754 42.0875,-70.9749 42.0879,-70.9752 42.0881,-70.9754 42.0891,-70.9758 42.0894,-70.9759 42.0897,-70.9759 42.0899,-70.9754 42.0902,-70.9756 42.0906,-70.9753 42.0907,-70.9753 42.0917,-70.9757 42.0924,-70.9755 42.0928,-70.9755 42.0942,-70.9751 42.0948,-70.9755 42.0953,-70.9751 42.0958,-70.9751 42.0962,-70.9759 42.0983,-70.9767 42.0987,-70.9768 42.0991,-70.9771 42.0997,-70.9771 42.1003,-70.9768 42.1005,-70.977 42.1011,-70.9766 42.1019,-70.9768 42.1026,-70.9769 42.1033,-70.9775 42.1042,-70.9773 42.1043,-70.9776 42.1043,-70.9778 42.1048,-70.9773 42.1058,-70.9774 42.1061,-70.9779 42.1065,-70.9782 42.1078,-70.9788 42.1085,-70.9798 42.1087,-70.9806 42.109,-70.9807 42.1093,-70.9806 42.1099,-70.9809 42.1109,-70.9808 42.1112,-70.9798 42.1116,-70.9792 42.1127,-70.979 42.1129,-70.9787 42.1134,-70.979 42.1139,-70.9791 42.1141,-70.9987 42.1116,-71.0022 42.1273,-70.9408 42.1513,-70.9315 42.1165,-70.916 42.1002)))See Also, ST_PointFromTextMakes a point Geometry from WKT with the given SRID. If SRID is
not given, it defaults to unknown.geometry ST_PointFromTexttext WKTgeometry ST_PointFromTexttext WKTinteger sridDescriptionConstructs a PostGIS ST_Geometry point object from the OGC Well-Known text representation. If SRID is
not given, it defaults to unknown (currently 0). If geometry is not a WKT point representation, returns null.
If completely invalid WKT, then throws an error.There are 2 variants of ST_PointFromText function, the first takes no SRID and returns a geometry
with no defined spatial reference system. The second takes a spatial reference id as the second argument
and returns an ST_Geometry that includes this srid as part of its meta-data. The srid must be defined
in the spatial_ref_sys table.If you are absolutely sure all your WKT geometries are points, don't use this function.
It is slower than ST_GeomFromText since it adds an additional validation step. If you are building points from long lat coordinates and care more about performance and accuracy than OGC compliance, use or OGC compliant alias . &sfs_compliant; s3.2.6.2 - option SRID is from the conformance suite.&sqlmm_compliant; SQL-MM 3: 6.1.8ExamplesCreate a point with the default SRID 0.SELECT ST_PointFromText('POINT(-71.064544 42.28787)');POINT(-71.064544 42.28787)Create a point with SRID 4326.SELECT ST_PointFromText('POINT(-71.064544 42.28787)', 4326);SRID=4326;POINT(-71.064544 42.28787)See Also, , , ST_PolygonFromTextMakes a Geometry from WKT with the given SRID. If SRID is
not given, it defaults to 0.geometry ST_PolygonFromTexttext WKTgeometry ST_PolygonFromTexttext WKTinteger sridDescriptionMakes a Geometry from WKT with the given SRID. If SRID is
not given, it defaults to 0. Returns null if WKT is not a polygon.OGC SPEC 3.2.6.2 - option SRID is from the conformance
suiteIf you are absolutely sure all your WKT geometries are polygons, don't use this function.
It is slower than ST_GeomFromText since it adds an additional validation step. &sfs_compliant; s3.2.6.2&sqlmm_compliant; SQL-MM 3: 8.3.6ExamplesThe result is returned as a native geometry. The documentation test runner
compares that value directly with the readable EWKT shown below and uses the same
geometry for the generated figure.SELECT ST_PolygonFromText('POLYGON((-71.1776585052917 42.3902909739571,-71.1776820268866 42.3903701743239,
-71.1776063012595 42.3903825660754,-71.1775826583081 42.3903033653531,-71.1776585052917 42.3902909739571))');POLYGON((-71.1776585052917 42.3902909739571,-71.1776820268866 42.3903701743239,-71.1776063012595 42.3903825660754,-71.1775826583081 42.3903033653531,-71.1776585052917 42.3902909739571))SELECT ST_PolygonFromText('POINT(1 2)') IS NULL AS point_is_notpoly;tSee AlsoST_WKTToSQLReturns a geometry from Well-Known Text (WKT). SQL/MM alias for ST_GeomFromText.geometry ST_WKTToSQLtext WKTDescriptionThis function is the SQL/MM alias for with no SRID argument.&sqlmm_compliant; SQL-MM 3: 5.1.34See AlsoWell-Known Binary (WKB)ST_GeogFromWKBCreates a geography instance from a Well-Known Binary geometry
representation (WKB) or extended Well Known Binary (EWKB).geography ST_GeogFromWKBbytea wkbDescriptionThe ST_GeogFromWKB function, takes a well-known
binary representation (WKB) of a geometry or PostGIS Extended WKB and creates an instance of the appropriate
geography type. This function plays the role of the Geometry Factory in
SQL. If SRID is not specified, it defaults to 4326 (WGS 84 long lat).&curve_support;ExamplesAlthough bytea rep contains single \, these need to be escaped when inserting into a table.SELECT ST_GeogFromWKB(E'\\001\\002\\000\\000\\000\\002\\000\\000\\000\\037\\205\\353Q\\270~\\\\\\300\\323Mb\\020X\\231C@\\020X9\\264\\310~\\\\\\300)\\\\\\217\\302\\365\\230C@');LINESTRING(-113.98 39.198,-113.981 39.195)See Also, ST_GeomFromEWKBReturn a specified ST_Geometry value from Extended Well-Known Binary representation (EWKB).geometry ST_GeomFromEWKBbytea EWKBDescriptionConstructs a PostGIS geometry from an Extended Well-Known Binary (EWKB) representation.The EWKB format is not an OGC standard, but a PostGIS specific format that includes the spatial reference system (SRID)
identifierEnhanced: 2.0.0 support for Polyhedral surfaces and TIN was introduced.&Z_support;&curve_support;&P_support;&T_support;ExamplesThis example constructs
LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932)
in NAD83 longitude/latitude (SRID 4269) from its EWKB representation.PostgreSQL escape string syntax (E'...') always interprets backslash escapes.
Each backslash therefore has to be doubled so that the bytea input parser receives the octal escapes.SELECT ST_GeomFromEWKB((
E'\\001\\002\\000\\000\\040\\255\\020\\000\\000\\003\\000\\000\\000\\344\\112\\075' ||
E'\\013\\102\\312\\121\\300\\156\\303\\050\\010\\036\\041\\105\\100\\047\\277\\105' ||
E'\\047\\113\\312\\121\\300\\366\\173\\142\\235\\052\\041\\105\\100\\225\\174\\354' ||
E'\\056\\120\\312\\121\\300\\160\\231\\323\\145\\061\\041\\105\\100'
)::bytea);0102000020AD10000003000000E44A3D0B42CA51C06EC328081E21454027BF45274BCA51C0F67B629D2A214540957CEC2E50CA51C07099D36531214540With standard_conforming_strings enabled (the default), ordinary string literals preserve
backslashes. The same EWKB can therefore be written with a single backslash before each octal byte value.SELECT ST_GeomFromEWKB((
'\001\002\000\000\040\255\020\000\000\003\000\000\000\344\112\075' ||
'\013\102\312\121\300\156\303\050\010\036\041\105\100\047\277\105' ||
'\047\113\312\121\300\366\173\142\235\052\041\105\100\225\174\354' ||
'\056\120\312\121\300\160\231\323\145\061\041\105\100'
)::bytea);0102000020AD10000003000000E44A3D0B42CA51C06EC328081E21454027BF45274BCA51C0F67B629D2A214540957CEC2E50CA51C07099D36531214540See Also, , ST_GeomFromWKBCreates a geometry instance from a Well-Known Binary geometry
representation (WKB) and optional SRID.geometry ST_GeomFromWKBbytea geomgeometry ST_GeomFromWKBbytea geominteger sridDescriptionThe ST_GeomFromWKB function, takes a well-known
binary representation of a geometry and a Spatial Reference System ID
(SRID) and creates an instance of the appropriate
geometry type. This function plays the role of the Geometry Factory in
SQL. This is an alternate name for ST_WKBToSQL.If SRID is not specified, it defaults to 0 (Unknown).&sfs_compliant; s3.2.7.2 - the optional SRID is from the conformance suite&sqlmm_compliant; SQL-MM 3: 5.1.41&curve_support;ExamplesAlthough bytea rep contains single \, these need to be escaped when inserting into a table. Unless standard_conforming_strings is set to on.SELECT ST_GeomFromWKB(E'\\001\\002\\000\\000\\000\\002\\000\\000\\000\\037\\205\\353Q\\270~\\\\\\300\\323Mb\\020X\\231C@\\020X9\\264\\310~\\\\\\300)\\\\\\217\\302\\365\\230C@', 4326);SRID=4326;LINESTRING(-113.98 39.198,-113.981 39.195)SELECT ST_GeomFromWKB(ST_AsEWKB('POINT(2 5)'::geometry)
);POINT(2 5)The PostgreSQL decode
function converts a hexadecimal WKB string to the bytea value
accepted by ST_GeomFromWKB.SELECT ST_AsEWKT(ST_GeomFromWKB(
decode('0101000000e5d022dbf93e2e40dbf97e6abc743540', 'hex'),
4326
)) AS geom;SRID=4326;POINT(15.123 21.456)See Also, , , ST_LineFromWKBCreates a LINESTRING from a WKB representation, optionally using a given SRID.geometry ST_LineFromWKBbytea WKBgeometry ST_LineFromWKBbytea WKBinteger sridDescriptionThe ST_LineFromWKB function takes a Well-Known Binary
(WKB) representation of a geometry and an optional Spatial Reference System
ID (SRID), and creates a LINESTRING
geometry. It is a type-specific geometry factory in SQL.If an SRID is not specified, it defaults to 0. NULL is
returned if the input bytea does not represent a
LINESTRING geometry.OGC SPEC 3.2.6.2 - optional SRID is from the conformance
suite.If you know all your geometries are LINESTRINGs, it is more
efficient to use directly. This function
calls and adds validation that the result is
a LINESTRING.&sfs_compliant; s3.2.6.2&sqlmm_compliant; SQL-MM 3: 7.2.9ExamplesSELECT ST_LineFromWKB(
ST_AsBinary(ST_GeomFromText('LINESTRING(1 2,3 4)'))
) AS aline,
ST_LineFromWKB(
ST_AsBinary(ST_GeomFromText('POINT(1 2)'))
) IS NULL AS null_return;
aline | null_return
------------------------------------
LINESTRING(1 2,3 4) | t
See Also, ST_LinestringFromWKBCreates a LINESTRING from a WKB representation, optionally using a given SRID.geometry ST_LinestringFromWKBbytea WKBgeometry ST_LinestringFromWKBbytea WKBinteger sridDescriptionThe ST_LinestringFromWKB function takes a Well-Known Binary
(WKB) representation of a geometry and an optional Spatial Reference System
ID (SRID), and creates a LINESTRING
geometry. It is an alias for .If an SRID is not specified, it defaults to 0. NULL is
returned if the input bytea does not represent a
LINESTRING geometry.OGC SPEC 3.2.6.2 - optional SRID is from the conformance suite.If you know all your geometries are LINESTRINGs, it is more
efficient to use directly. This function
calls and adds validation that the result is
a LINESTRING.&sfs_compliant; s3.2.6.2&sqlmm_compliant; SQL-MM 3: 7.2.9ExamplesSELECT ST_LinestringFromWKB(
ST_AsBinary(ST_GeomFromText('LINESTRING(1 2,3 4)'))
) AS aline,
ST_LinestringFromWKB(
ST_AsBinary(ST_GeomFromText('POINT(1 2)'))
) IS NULL AS null_return;
aline | null_return
------------------------------------
LINESTRING(1 2,3 4) | tSee Also, ST_PointFromWKBMakes a geometry from WKB with the given SRIDgeometry ST_GeomFromWKBbytea geomgeometry ST_GeomFromWKBbytea geominteger sridDescriptionThe ST_PointFromWKB function, takes a well-known binary
representation of geometry and a Spatial Reference System ID (SRID)
and creates an instance of the appropriate geometry type - in this case, a
POINT geometry. This function plays the role of the Geometry
Factory in SQL.If an SRID is not specified, it defaults to 0. NULL is
returned if the input bytea does not represent a
POINT geometry.&sfs_compliant; s3.2.7.2&sqlmm_compliant; SQL-MM 3: 6.1.9&Z_support;&curve_support;ExamplesSELECT ST_PointFromWKB(ST_AsEWKB('POINT(2 5)'::geometry));POINT(2 5)SELECT ST_PointFromWKB(ST_AsEWKB('LINESTRING(2 5,2 6)'::geometry));nullSee Also, ST_WKBToSQLReturns a geometry from Well-Known Binary (WKB). SQL/MM alias for ST_GeomFromWKB without an SRID argument.geometry ST_WKBToSQLbytea WKBDescriptionThis function is the SQL/MM alias for with no SRID argument.&sqlmm_compliant; SQL-MM 3: 5.1.36See AlsoOther FormatsST_Box2dFromGeoHashReturn a BOX2D from a GeoHash string.box2d ST_Box2dFromGeoHashtext geohashinteger precision=full_precision_of_geohashDescriptionReturn a BOX2D from a GeoHash string.If no precision is specified ST_Box2dFromGeoHash returns a BOX2D based on full precision of the input GeoHash string.If precision is specified ST_Box2dFromGeoHash will use that many characters from the GeoHash to create the BOX2D. Lower precision values results in larger BOX2Ds and larger values increase the precision.Availability: 2.1.0ExamplesSELECT ST_Box2dFromGeoHash('9qqj7nmxncgyy4d0dbxqz0');BOX(-115.172816 36.114646,-115.172816 36.114646)SELECT ST_Box2dFromGeoHash('9qqj7nmxncgyy4d0dbxqz0', 0);BOX(-180 -90,180 90)SELECT ST_Box2dFromGeoHash('9qqj7nmxncgyy4d0dbxqz0', 10);BOX(-115.17282128334 36.1146408319473,-115.172810554504 36.1146461963654)See Also, , ST_GeomFromGeoHashReturn a geometry from a GeoHash string.geometry ST_GeomFromGeoHashtext geohashinteger precision=full_precision_of_geohashDescriptionReturn a geometry from a GeoHash string. The geometry will be a polygon representing the GeoHash bounds.If no precision is specified ST_GeomFromGeoHash returns a polygon based on full precision of the input GeoHash string.If precision is specified ST_GeomFromGeoHash will use that many characters from the GeoHash to create the polygon.Availability: 2.1.0ExamplesThe cells are returned together so their relative sizes remain visible in a shared coordinate frame.SELECT ST_GeomFromGeoHash('9qqj7nmxncgyy4d0dbxqz0', 4) AS "precision 4", ST_GeomFromGeoHash('9qqj7nmxncgyy4d0dbxqz0', 5) AS "precision 5", ST_GeomFromGeoHash('9qqj7nmxncgyy4d0dbxqz0', 6) AS "precision 6";-[ RECORD 1 ]----------
precision 4 | POLYGON((-115.3125 36.03515625,-115.3125 36.2109375,-114.9609375 36.2109375,-114.9609375 36.03515625,-115.3125 36.03515625))
precision 5 | POLYGON((-115.1806640625 36.0791015625,-115.1806640625 36.123046875,-115.13671875 36.123046875,-115.13671875 36.0791015625,-115.1806640625 36.0791015625))
precision 6 | POLYGON((-115.1806640625 36.112060546875,-115.1806640625 36.1175537109375,-115.169677734375 36.1175537109375,-115.169677734375 36.112060546875,-115.1806640625 36.112060546875))See Also,, ST_GeomFromGMLTakes as input GML representation of geometry and outputs a PostGIS geometry objectgeometry ST_GeomFromGMLtext geomgmlgeometry ST_GeomFromGMLtext geomgmlinteger sridDescriptionConstructs a PostGIS ST_Geometry object from the OGC GML representation.ST_GeomFromGML works only for GML Geometry fragments. It throws an error if you try to use it on a whole GML document.
OGC GML versions supported:
GML 3.2.1 NamespaceGML 3.1.1 Simple Features profile SF-2 (with GML 3.1.0 and 3.0.0 backward compatibility)GML 2.1.2
OGC GML standards, cf: http://www.opengeospatial.org/standards/gml:
Availability: 1.5, requires libxml2 1.6+Enhanced: 2.0.0 support for Polyhedral surfaces and TIN was introduced.Enhanced: 2.0.0 default srid optional parameter added.Enhanced: 3.7.0 support for GML ArcString, curved Ring, and CurvePolygon geometries was introduced.&Z_support;&P_support;&T_support;GML allow mixed dimensions (2D and 3D inside the same MultiGeometry for instance). As PostGIS geometries don't, ST_GeomFromGML convert the whole geometry to 2D if a missing Z dimension is found once.GML support mixed SRS inside the same MultiGeometry. As PostGIS geometries don't, ST_GeomFromGML, in this case, reproject all subgeometries to the SRS root node. If no srsName attribute available for the GML root node, the function throw an error.ST_GeomFromGML function is not pedantic about an explicit GML namespace. You could avoid to mention it explicitly for common usages. But you need it if you want to use XLink feature inside GML.ExamplesA single geometry with srsName.
-71.16028,42.258729 -71.160837,42.259112 -71.161143,42.25932
$$));
]]>
SRID=4269;LINESTRING(-71.16028 42.258729,-71.160837 42.259112,-71.161143 42.25932)XLink usage.-71.16028 42.258729-71.160837 42.259112-71.161143 42.258729
$$));
]]>
SRID=4269;LINESTRING(-71.16028 42.258729,-71.160837 42.259112,-71.161143 42.258729,-71.16028 42.258729)Polyhedral Surface.0 0 0 0 0 1 0 1 1 0 1 0 0 0 00 0 0 0 1 0 1 1 0 1 0 0 0 0 00 0 0 1 0 0 1 0 1 0 0 1 0 0 01 1 0 1 1 1 1 0 1 1 0 0 1 1 00 1 0 0 1 1 1 1 1 1 1 0 0 1 00 0 1 1 0 1 1 1 1 0 1 1 0 0 1
'));
]]> POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),
((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),
((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),
((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),
((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),
((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)))See Also, , ST_GeomFromGeoJSONTakes as input a geojson representation of a geometry and outputs a PostGIS geometry objectgeometry ST_GeomFromGeoJSONtext geomjsongeometry ST_GeomFromGeoJSONjson geomjsongeometry ST_GeomFromGeoJSONjsonb geomjsonDescriptionConstructs a PostGIS geometry object from the GeoJSON representation.ST_GeomFromGeoJSON works only for JSON Geometry fragments. It throws an error if you try to use it on a whole JSON document.Enhanced: 3.0.0 parsed geometry defaults to SRID=4326 if not specified otherwise.Enhanced: 2.5.0 can now accept json and jsonb as inputs.Availability: 2.0.0 requires - JSON-C >= 0.9If you do not have JSON-C enabled, support you will get an error notice instead of seeing an output.
To enable JSON-C, run configure --with-jsondir=/path/to/json-c. See for details.&Z_support;ExamplesSELECT ST_GeomFromGeoJSON('{"type":"Point","coordinates":[-48.23456,20.12345]}') AS wkt;POINT(-48.23456 20.12345)This example creates a 3D LineString.SELECT ST_GeomFromGeoJSON('{"type":"LineString","coordinates":[[1,2,3],[4,5,6],[7,8,9]]}') AS wkt;LINESTRING Z (1 2 3,4 5 6,7 8 9)See Also, , ST_GeomFromKMLTakes as input KML representation of geometry and outputs a PostGIS geometry objectgeometry ST_GeomFromKMLtext geomkmlDescriptionConstructs a PostGIS geometry from an OGC KML representation.ST_GeomFromKML works only for KML Geometry fragments. It throws an error if you try to use it on a whole KML document.
OGC KML versions supported:
KML 2.2.0 Namespace
OGC KML standards, cf: http://www.opengeospatial.org/standards/kml:
Availability: 1.5, requires libxml2 2.6+&Z_support;ST_GeomFromKML does not support SQL/MM curve geometries.ExamplesA single LineString geometry.-71.1663, 42.2614
-71.1667, 42.2616
$$));
]]>
SRID=4326;LINESTRING(-71.1663 42.2614,-71.1667 42.2616)See Also, ST_GeomFromTWKBCreates a geometry instance from a TWKB ("Tiny Well-Known Binary") geometry
representation.geometry ST_GeomFromTWKBbytea twkbDescriptionThe ST_GeomFromTWKB function, takes a a TWKB ("Tiny Well-Known Binary") geometry representation (WKB) and creates an instance of the appropriate
geometry type.ExamplesSELECT ST_GeomFromTWKB(ST_AsTWKB('LINESTRING(126 34,127 35)'::geometry));LINESTRING(126 34, 127 35)SELECT ST_GeomFromTWKB(E'\\x620002f7f40dbce4040105');LINESTRING(-113.98 39.198,-113.981 39.195)See AlsoST_GMLToSQLReturns a geometry from GML. Alias for ST_GeomFromGML.geometry ST_GMLToSQLtext geomgmlgeometry ST_GMLToSQLtext geomgmlinteger sridDescriptionThis function is an alias for and provides the same signatures.&sqlmm_compliant; SQL-MM 3: 5.1.50.Availability: 1.5, requires libxml2 1.6+Enhanced: 2.0.0 support for Polyhedral surfaces and TIN was introduced.Enhanced: 2.0.0 default srid optional parameter added.Enhanced: 3.7.0 support for GML ArcString, curved Ring, and CurvePolygon geometries was introduced.See Also, , ST_LineFromEncodedPolylineCreates a LineString from an Encoded Polyline.geometry ST_LineFromEncodedPolylinetext polylineinteger precision=5DescriptionCreates a LineString from an Encoded Polyline string.Optional precision specifies how many decimal places will be preserved in Encoded Polyline. Value should be the same on encoding and decoding, or coordinates will be incorrect.See http://developers.google.com/maps/documentation/utilities/polylinealgorithmAvailability: 2.2.0ExamplesThis example creates a LineString from a polyline.SELECT ST_LineFromEncodedPolyline('_p~iF~ps|U_ulLnnqC_mqNvxq`@');SRID=4326;LINESTRING(-120.2 38.5,-120.95 40.7,-126.453 43.252)This example selects a different precision than the one used for polyline encoding.SELECT ST_LineFromEncodedPolyline('_p~iF~ps|U_ulLnnqC_mqNvxq`@', 6);SRID=4326;LINESTRING(-12.02 3.85,-12.095 4.07,-12.6453 4.3252)
See AlsoST_PointFromGeoHashReturn a point from a GeoHash string.point ST_PointFromGeoHashtext geohashinteger precision=full_precision_of_geohashDescriptionReturn a point from a GeoHash string. The point represents the center point of the GeoHash.If no precision is specified ST_PointFromGeoHash returns a point based on full precision of the input GeoHash string.If precision is specified ST_PointFromGeoHash will use that many characters from the GeoHash to create the point.Availability: 2.1.0ExamplesSELECT ST_PointFromGeoHash('9qqj7nmxncgyy4d0dbxqz0');POINT(-115.172816 36.114646)SELECT ST_PointFromGeoHash('9qqj7nmxncgyy4d0dbxqz0', 4);POINT(-115.13671875 36.123046875)SELECT ST_PointFromGeoHash('9qqj7nmxncgyy4d0dbxqz0', 10);POINT(-115.172815918922 36.1146435141563)See Also, , ST_FromFlatGeobufToTableCreates a table based on the structure of FlatGeobuf data.void ST_FromFlatGeobufToTabletext schemanametext tablenamebytea FlatGeobuf input dataDescription
Creates a table based on the structure of FlatGeobuf data. (http://flatgeobuf.org).
schema Schema name.table Table name.data Input FlatGeobuf data.Availability: 3.2.0ST_FromFlatGeobufReads FlatGeobuf data.setof anyelement ST_FromFlatGeobufanyelement Table referencebytea FlatGeobuf input dataDescription
Reads FlatGeobuf data (http://flatgeobuf.org).
NOTE: PostgreSQL bytea cannot exceed 1GB.
tabletype reference to a table type.data input FlatGeobuf data.Availability: 3.2.0