Because of my problem with spatial queries (INTERSECTS) not working properly on a layer with SRID = -1 created with ogr2ogr - I need to force SRID of the geometry attribute of the layer to be automatically guesed or set it through the code during or after the layer creation process:
SQL View of the table:
SELECT * FROM "e2b0ad81_8888_4cd4_b455_6060e4cbea3e"
When I do "Guess geometry type and srid" here (GeoServer admin panel) - it guesses SRID right, ao I think it could be done automatically somehow
I found a messed up way around the problem:
Turned out that config that specifies the SRID field lays not in the DB but inside GeoServer container itself - somwhere like:
/opt/services/storage/%BD name?%/geoserver/data_dir/workspaces/%BD user?%/database/%LAYER NAME%/featuretype.xml
And after adding/modifiyng (top lavel) this to the XML file:
<geometry>
<name>the_geom</name>
<type>Geometry</type>
<srid>3857</srid>
</geometry>
And after restarting container with GeoServer - the changes aplayes and spatial queries work
Is there any better way to do this?
Preferably without restarting anything
Layer ogr2ogr command:
ogr2ogr -progress -overwrite -nln e2b0ad81_8888_4cd4_b455_6060e4cbea3e -t_srs EPSG:3857 -lco GEOMETRY_NAME=the_geom -lco FID=fid -dialect OGRSQL -sql "%ATTRS CREATION SQL% string" -s_srs EPSG:3857 PG:host=%HOST% port=%PORT% user=%USER% dbname=%DBNAME% password=%PW% 'sridtest.gpkg'
Geometry attribute SQL creation line:
the_geom geometry(Point,3857),
Full layer table SQL creation script:
CREATE TABLE IF NOT EXISTS public."e2b0ad81_8888_4cd4_b455_6060e4cbea3e"
(
fid integer NOT NULL DEFAULT nextval('"e2b0ad81_8888_4cd4_b455_6060e4cbea3e_fid_seq"'::regclass),
attr_0 character varying COLLATE pg_catalog."default",
...
attr_21 character varying COLLATE pg_catalog."default",
the_geom geometry(Point,3857),
CONSTRAINT "e2b0ad81_8888_4cd4_b455_6060e4cbea3e_pkey" PRIMARY KEY (fid)
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."e2b0ad81_8888_4cd4_b455_6060e4cbea3e"
OWNER to mapuser;
REVOKE ALL ON TABLE public."e2b0ad81_8888_4cd4_b455_6060e4cbea3e" FROM replicator;
GRANT ALL ON TABLE public."e2b0ad81_8888_4cd4_b455_6060e4cbea3e" TO mapuser;
GRANT SELECT ON TABLE public."e2b0ad81_8888_4cd4_b455_6060e4cbea3e" TO replicator;
-- Index: e2b0ad81_8888_4cd4_b455_6060e4cbea3e_geom_geom_idx
-- DROP INDEX IF EXISTS public."e2b0ad81_8888_4cd4_b455_6060e4cbea3e_geom_geom_idx";
CREATE INDEX IF NOT EXISTS "e2b0ad81_8888_4cd4_b455_6060e4cbea3e_geom_geom_idx"
ON public."e2b0ad81_8888_4cd4_b455_6060e4cbea3e" USING gist
(the_geom)
TABLESPACE pg_default;
Versions:
GeoServer 2.17.2
GeoTools 23.2 (rev 3a74d70c88a384047c14ebcb77420d0bd0ba0fc2)
GeoWebCache 1.17.2 (rev 1.17.x/b5344b575976fe578594157fb9a90cb399f8b272)