2016-09-22 2 views
0

Ich bekomme, was wie ein Fehler in Postgresql/Postgis scheint. Dies ist ein vollständig reproduzierbar Beispiel, das das Problem veranschaulicht:Postgresql/Postgis Fehler in ST_ApproximateMedialAxis?

#create a new srid for local area (formula for proj4text is taken from Quantum GIS) 
INSERT INTO spatial_ref_sys (srid, auth_name, auth_srid, proj4text) VALUES (998997, 'EPSG', 998997, '+proj=tmerc +lat_0=0 +lon_0=44.55 +k=1 +x_0=2250000 +y_0=-5714743.504 +ellps=krass +towgs84=24,-123,-94,0.02,-0.25,-0.13,1.1 +units=m +no_defs '); 

#create a new table for storing geometry data: 
CREATE TABLE layer(
    id SERIAL PRIMARY KEY, 
    geom geometry, 
    CONSTRAINT enforce_dims_geom_layer CHECK (st_ndims(geom) = 2), 
    CONSTRAINT enforce_srid_geom_layer CHECK (st_srid(geom) = 998997) 
); 

#add one polygon to the table: 
INSERT INTO layer (geom) VALUES (ST_Force2D(ST_Transform(ST_GeomFromText('POLYGON((4832654.676302 7570323.2813639, 4810946.560269 7597840.6115465, 4836629.4017728 7629944.1634263, 4886772.0923279 7629944.1634263, 4902059.4979849 7591725.6492837, 4864452.4800686 7553507.1351411, 4832654.676302 7570323.2813639),(4845190.3489408 7589891.1606049, 4855585.7847875 7610376.2841853, 4876988.1527074 7604567.0700356, 4874847.9159154 7588362.4200392, 4858031.7696927 7575520.9992872, 4845190.3489408 7589891.1606049))', 3857),998997))); 

#check that this polygon is valid! 
SELECT ST_IsValid(ST_Force2D(ST_Transform(ST_GeomFromText('POLYGON((4832654.676302 7570323.2813639, 4810946.560269 7597840.6115465, 4836629.4017728 7629944.1634263, 4886772.0923279 7629944.1634263, 4902059.4979849 7591725.6492837, 4864452.4800686 7553507.1351411, 4832654.676302 7570323.2813639),(4845190.3489408 7589891.1606049, 4855585.7847875 7610376.2841853, 4876988.1527074 7604567.0700356, 4874847.9159154 7588362.4200392, 4858031.7696927 7575520.9992872, 4845190.3489408 7589891.1606049))', 3857),998997))) AS is_valid; 
#^^^ it returns t. so, the geometry is 100% ok. 

#check how it looks like in geojson format: 
SELECT ST_AsGeoJSON(ST_Transform(geom, 3857))::json from layer 
#^^^ Again it's ok and returns some nice geojson data 

#Final step. Check ST_ApproximateMedialAxis function 
SELECT ST_ApproximateMedialAxis(ST_Transform(geom, 3857)) from layer; 

Die letzte Abfrage gibt eine Fehlermeldung:

ERROR: Polygon is invalid : exterior ring and interior ring 0 have the same orientation : POLYGON((5189023446929109/1073741824 2032143182100511/268435456,5165714534831303/1073741824 31867653268373/4194304,1298322818976529/268435456 8192590163056015/1073741824,26

********** Error **********

Also, alle Zutaten scheinen in Ordnung zu sein - Formel für srid von einigem Standard genommen wird weit verbreitetes Tool, Daten werden in die Tabelle ohne Probleme eingefügt, die Daten werden von ST_IsValid validiert, Geojson-Darstellung von Daten ist auch in Ordnung, aber eine Bibliotheksfunktion mag noch etwas nicht.

Antwort

2

Ich habe diese nette thread gefunden und kam zur Lösung. Ich habe nur ST_ForceRHR Postgis Funktion verwenden, die

forces the orientation of the vertices in a polygon to follow the Right-Hand-Rule

So ist der richtige Weg, um die Daten einzufügen war:

INSERT INTO layer (geom) VALUES (ST_Force2D(ST_Transform(ST_ForceRHR(ST_GeomFromText('POLYGON((4832654.676302 7570323.2813639, 4810946.560269 7597840.6115465, 4836629.4017728 7629944.1634263, 4886772.0923279 7629944.1634263, 4902059.4979849 7591725.6492837, 4864452.4800686 7553507.1351411, 4832654.676302 7570323.2813639),(4845190.3489408 7589891.1606049, 4855585.7847875 7610376.2841853, 4876988.1527074 7604567.0700356, 4874847.9159154 7588362.4200392, 4858031.7696927 7575520.9992872, 4845190.3489408 7589891.1606049))', 3857)),998997))); 
Verwandte Themen