9

I have a Spatialite layer which is multipoint (following a QGIS Save As from shapefile). I need it to be PostGIS and POINT. I have tried ogr2ogr -nlt POINT and got 'new row for relation "xxx" violates check constraint "enforce_geotype_geometry"' error on insert.

I've also tried converting within PostGIS - i.e. bringing the layer in as multipoint and converting to point - no joy.

I'm using PostGIS 1.5.3 PostGreSQL 9.1.8. (considering upping to PostGIS2 after reading this: How to change the geometry type from Point to Multipoint within an existing table in PostGIS?) but would prefer to stay at 1.5 for now if there's a way round this. Happy to do this in either spatialite or PostGIS.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Mar 21, 2013 at 7:10

4 Answers 4

14

SpatialLite has no way of converting multi-geometries to single-parts itself. There are some 'CastTo' functions but they are for special cases (where your multigeometry contains a single geometry - it won't fan-out). I have seen a reference to a function in the SpatialLite GUI but never found it (perhaps you need to compile from the latest source code. I'm just using a pre-compiled binary). So your best bets are:

  • In PostGIS you can use ST_Dump. This is a useful function for expanding multi-geometries.
  • In QGIS you could use Vector->Geometry Tools->Multipart to singlepart
answered Mar 21, 2013 at 9:15
12

You can convert multipoint layer to single points with menu Vector -> Geometry tools -> Multipart to Singleparts and import the new layer into PostGIS.

answered Mar 22, 2013 at 1:50
2
  • Yes, that's got to be easier. The only problem with Multipart to Singleparts is you have to first save the layer as a shapefile - so you lose your nice long column names, but it's certainly easier on my brain! Commented Mar 22, 2013 at 6:35
  • @minisaurus: your multipoint layer may be spatialite but the result of conversion (single point layer) will be shapefile - so yes, you may lose your nice long column names but you can change them back manually in PostGIS. Commented Mar 22, 2013 at 7:29
0

Do you have access to ArcGIS? There is "multipart to singlepart" in ArcGIS, see http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000003r000000 .

answered Mar 21, 2013 at 8:22
1
  • No - I have QGIS tho' Commented Mar 21, 2013 at 9:13
0

I've done it but can't remember all the steps unfortunately:

  1. ogr2ogr table to PostGIS
  2. created a new table as a copy of this table's structure
  3. dropped the geometry column in the new table
  4. created a new geometry column as point (select AddGeometryColumn etc)
  5. inserted the data from the multipoint table into the new table (this is the bit I have forgotten how I did)
  6. created a spatial index on the new tables geometry table

There must be an easier way.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Mar 21, 2013 at 15:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.