Top 5 Recent Articles
ARTICLES CATEGORIES
- Algorithms (22)
- All (399)
- Biography (1)
- Blog (44)
- Business Requirements (1)
- Commentary (1)
- Conversion (2)
- Customers (2)
- Data Models (1)
- Education (2)
- GeoRaptor (13)
- GPS (1)
- Image Processing (2)
- Import Export (8)
- Licensing (2)
- LiDAR (1)
- Linear Referencing (4)
- Manifold GIS (3)
- Mapping (1)
- MySQL Spatial (7)
- Networking and Routing (including Optimization) (5)
- Open Source (18)
- Oracle Spatial and Locator (194)
- Partitioning (1)
- PostGIS (36)
- Projections (1)
- Published Articles (1)
- qGIS (1)
- Recommendations (1)
- Services (1)
- Software Change Log (1)
- Source Code (37)
- Space Curves (9)
- Spatial Database Functions (109)
- Spatial DB comparison (1)
- Spatial XML Processing (11)
- SQL Server Spatial (92)
- Standards (3)
- Stored Procedure (17)
- Tessellation or Gridding (10)
- Tools (2)
- Topological Relationships (1)
- Training (2)
- Triangulation (2)
Processing GML data using PostgreSQL’s XMLTABLE
XMLTABLE was added to PostgreSQL at version 10.
All examples of how to process spatial XML on this site for PostgreSQL/PostGIS were based on 9.x.
Here is an example of how to process GML using XMLTABLE.
With hoteldata as (
SELECT '<hotels>
<hotel id="mancha">
<name>La Mancha</name>
<location>
<Point srsName="EPSG:4326">
<pos>-43.23737 147.14756</pos>
</Point>
</location>
<rooms>
<room id="201">
<capacity>3</capacity>
<comment>Great view of the Channel</comment>
<location>
<Point srsName="EPSG:4326">
<pos>-43.23731 147.14751</pos>
</Point>
</location>
</room>
<room id="202">
<capacity>5</capacity>
<location>
<Point srsName="EPSG:4326">
<pos>-43.23732 147.14758</pos>
</Point>
</location>
</room>
</rooms>
</hotel>
<hotel id="valpo">
<name>Valparaíso</name>
<location>
<Point srsName="EPSG:4326">
<pos>-43.26737 147.29756</pos>
</Point>
</location>
<rooms>
<room id="201">
<capacity>2</capacity>
<comment>Very noisy</comment>
<location>
<Point srsName="EPSG:4326">
<pos>-43.26729 147.29750</pos>
</Point>
</location>
</room>
<room id="202">
<capacity>2</capacity>
<location>
<Point srsName="EPSG:4326">
<pos>-43.26741 147.29734</pos>
</Point>
</location>
</room>
<room id="203">
<capacity>4</capacity>
<comment>Very comfortable</comment>
<location>
<Point srsName="EPSG:4326">
<pos>-43.26740 147.29760</pos>
</Point>
</location>
</room>
</rooms>
</hotel>
</hotels>'::xml as hotels
)
SELECT decoded.room_id,
decoded.capacity,
decoded.comment,
ST_AsEWKT(
ST_GeomFromGML(decoded.location::text,4326)
) as geom
FROM
hoteldata
cross join
xmltable(
'//hotels/hotel/rooms/room'
passing hotels
COLUMNS
room_id varchar(3) path '@id',
location xml path 'location/Point',
capacity integer,
comment text
) AS decoded;
The result is as follows:
| room_id | capacity | comment | geom |
|---|---|---|---|
| 201 | 3 | Great view of the Channel | SRID=4326;POINT(-43.23731 147.14751) |
| 202 | 5 | SRID=4326;POINT(-43.23732 147.14758) | |
| 201 | 2 | Very noisy | SRID=4326;POINT(-43.26729 147.2975) |
| 202 | 2 | SRID=4326;POINT(-43.26741 147.29734) | |
| 203 | 4 | Very comfortable | SRID=4326;POINT(-43.2674 147.2976) |
I hope this is useful to someone.
Documentation
- GeoRaptor Documentation
- MySQL Spatial General Functions
- Oracle LRS Objects
- Oracle Spatial Exporter (Java + pl/SQL)
- Oracle Spatial Object Functions
- Oracle Spatial Object Functions (Multi Page)
- PostGIS pl/pgSQL Functions
- SC4O Oracle Java Topology Suite (Java + pl/SQL)
- SQL Server Spatial General TSQL Functions
- SQL Server Spatial LRS TSQL Functions