Sunday, 19 August 2018

Geojson in postgis Geometry : Z dimension error


i had this php code :


$geom1='{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-32514.400906806848,4810093.013501738],[-32877.47679116143,4809500.626532529],[-34473.099756614494,4810026.131101989],[-33412.535989157666,4811124.913383588],[-32514.400906806848,4810093.013501738]]]},"properties":null}';
$geom_poly=explode('Polygon',$geom1);
$geom_def=$geom_poly[0]."MultiPolygon".$geom_poly[1];
$geom2=explode('{',$geom_def);
$geom3=explode('}',$geom2[2]);
$CRS='"crs":{"type":"name","properties":{"name":"EPSG:3857"}}';
$geometria1=$geom3[0];
$geom4='{'.$geometria1.'},'.$CRS;





$uso_edit = $_POST['uso'];
$afeccion_edit = $_POST['afeccion'];
$retablo_edit = $_POST['retablo'];
$proteccion_edit = $_POST['proteccion'];
$altura_edit = $_POST['altura'];
$query = "INSERT INTO prueba(geom,prueba) VALUES ( ST_SetSRID(ST_GeomFromGeoJSON('".$geom4."'),3857) , 'jsadfjlasd') ";

pg_exec($query);

I had this error :


pg_exec(): Query failed: ERROR: Geometry has Z dimension but column does not in


My PostgreSQL version is 9.4: and my table code is :


CREATE TABLE prueba
(
id_0 serial NOT NULL,
geom geometry(MultiPolygon,3857),
id integer,

prueba character varying(80),
CONSTRAINT prueba_pkey PRIMARY KEY (id_0)
)
WITH (
OIDS=FALSE
);
ALTER TABLE prueba
OWNER TO postgres;

I try change the dimension with :



ALTER TABLE urbana_prueba  
ALTER COLUMN geom TYPE geometry(MultiPolygon, 3857)
USING ST_Force_3D(geom);

but dosen't work......



Answer



You were almost there...


MultiPolygonZ should do the trick:


ALTER TABLE urbana_prueba  
ALTER COLUMN geom TYPE geometry(MultiPolygonZ, 3857)

USING ST_Force_3D(geom);

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...