Geoserver - Connect to a SQL Server 2008 Express and fetch data
-Bref history:-
I was using MapServer, everything was working fine except that when I was drawing a marker directly on a layer using a PixMap it was cut between tile. So, I decided to change to GeoServer which looks to work correctly to draw tiles where you have some image/pixmap between tiles.
-End of history-
Ok, I am able to connect to my data store which is Ms Sql Server 2008 (Express edition). Perhaps, I am not able to show anything on my OpenLayer map.
Example of point in my database:
POINT (2.66131 48.8792)
POINT (2.66131 48.8792)
POINT (2.67789 48.8982)
POINT (2.67789 48.8982)
POINT (2.70361 48.9402)
POINT (2.76454 48.9866)
In my GeoServer 2.0.2, I actually use the default style for point (Red square point). The EPSG of these point in the database is "4326" and in the configuration of GeoServer, it is also 4326 with boundaries like this:
Min X: 2
Min Y: 46
Max X: 8
Max Y: 50
Have I done something wrong to not be able to show any points?
Edit Here's the definition of my table
id int (PK)
lon float
lat float
geom geometry
Here's an example of the query coming from GeoServer:
SELECT "id",CAST("geom".STSrid as VARCHAR) + ':' + "geom".STAsText() as "geom" FROM "TestGeom" WHERE "geom".Filter(geometry::STGeomFromText('POLYGON ((-236.25 -120.234375, -236.2开发者_开发知识库5 120.234375, 236.25 120.234375, 236.25 -120.234375, -236.25 -120.234375))', 0)) = 1
It returns a list of points only if I set my EPSG in the database to 0 (they still don't show in the openlayer "preview"). If I leave it at 4326, it returns nothing. The polygon drawn by geoserver is in EPSG:0.
For those who encounter the same issue:
I found the reason why it was not working. The "Native-SRC" was not setting itself properly (in fact I had no value at all). This is actually the main reason why I wasn't able to see anything. Now for no good reason (or miracle), after removing everything and re-creating everything, I now have a Native SRC value and everything shows up as expected.
In fact the database when I added it to the GeoServer, the tables were setted with EPSG:0 (default for geometry). But you need to switch the EPSG to 4326 by doing an update like this:
update MyTable set MyGeom = geometry::...FromText(MyGeom.STAsText(), 4326)
After, remove all the reference in GeoServer to your table. You actually need to recreate everything from scratch. And when you will re-add your database with your table, it will work. In fact, you will see the "Native-SRC" to be set by itself, and you can also click on the autoset the BBOX of your table. (Min X, Y, Max X, Y)
精彩评论