Moments Booth
Moments Booth

Reputation: 1

Is there a solution to fix the preview for a sql server layer in Geoserver?

I have a layer that is coming from a SQL Server Database, the database has been linked to GeoServer and I can import all the layers from database in my GeoServer.

When I publish a layer and I'm trying to preview it, i receive the error message that is displayed in the image geoserver

I made some research and I came to conclusion that the GeoServer is not able to display my layer because the layers doesn't have the SRID (projection defined) inside of the SQL Server Database. I will attach an image of the records that of the layer sql_data

Is there a solution to this problem?

I want to be able to preview the layer in GeoServer

Upvotes: 0

Views: 125

Answers (1)

Moments Booth
Moments Booth

Reputation: 1

I found the solution🎉

When you import a .shp into the SQL Server database, the imported file does not come with an SRID (the projection is not defined). To fix this you need to specify manually the SRID code.

After that, you need to create a table using this script:

CREATE TABLE GEOMETRY_COLUMNS(
   F_TABLE_SCHEMA VARCHAR(30) NOT NULL,
   F_TABLE_NAME VARCHAR(30) NOT NULL,
   F_GEOMETRY_COLUMN VARCHAR(30) NOT NULL,
   COORD_DIMENSION INTEGER,
   SRID INTEGER NOT NULL,
   TYPE VARCHAR(30) NOT NULL,
   UNIQUE(F_TABLE_SCHEMA, F_TABLE_NAME, F_GEOMETRY_COLUMN),
   CHECK(TYPE IN ('POINT', 'LINESTRING', 'POLYGON', 'MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION') ));

In this table you need to insert:

  • F_TABLE_SCHEMA - dbo in most cases
  • F_TABLE_NAME - name of your table
  • F_GEOMETRY_COLUMN - column where is stored geometry in your table
  • COORD_DIMENSION - 2 is for coordinates that contain X,Y - 3 is for coordinates that contain X,Y,Z
  • SRID - 3844 (EPSG code)
  • TYPE - POINT (or LINESTRING,POLYGON, etc.)

After that, you need to go GeoServer and set up the connection to your database, and in the bottom of the page you need to specify the geometry table:

see image

After all these steps you will be able to preview the layer in GeoServer

Upvotes: 0

Related Questions