GeoTools+MySQL

5 messages Options
Embed this post
Permalink
iceDice

GeoTools+MySQL

Reply Threaded More More options
Print post
Permalink
Hello,

I have problems to show data from MySQL db on map.

I try to do that on following way:

Map params = new HashMap();
params.put("dbtype", "mysql");
params.put("host", "localhost");
params.put("port", new Integer(3306));
params.put("database", "my_db");
params.put("user", "root");

MySQLDataStoreFactory mySQLFactory = new MySQLDataStoreFactory();
MySQLDataStore mySQLDatastore = (MySQLDataStore) mySQLFactory.createDataStore(params);
// Prepare feature sources
fsStreets = mySQLDatastore.getFeatureSource("streets");

When i tried to display layer on JMapFrame i can't see anything. Values for map bounds in JMapFrame
Status bar (min and max Lat and Lon) are all NaN.

I check ogrinfo MySQL:my_db,user=root streets -so and get:
INFO: Open of `MySQL:my_db,user=root' using driver `MySQL' successful.
Layer name: streets
Geometry: Line String
Feature Count: 930
Extent: (19.559141, 46.026719) - (19.801404, 46.168960)
Layer SRS WKT:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.01745329251994328,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]
FID Column = OGR_FID
Geometry Column = SHAPE
name: String (254.0)
oneway: String (254.0)
type: String (1.0)

What can be problem here? I make table in MySQL from shapefile without .prj file with
following command: ogr2ogr -f "MySQL" MYSQL:"my_db,host=localhost,user=root,port=3306" -nln "streets" -a_srs "EPSG:4326" streets.shp

Also i try all of this with Postgis and everything works perfect.

I hope so someone can help me about this.

Best regards
iceDice

Re: GeoTools+MySQL

Reply Threaded More More options
Print post
Permalink
Hello again,

I have made additional testing and i have following situation:

When i add some layers from other data sources (shapefiles, postgres)
and then add layer from mysql db i got all data displayed, but zoomed to
layer from shapefile or postgres. But when i load only data from mysql i
can't see anything. It seems to me that map bounds cannot be determined
at all when using only mysql. I don't know what i am doing wrong, i use ogr2ogr
to transform data from shapefile to mysql with option to keep CRS (-s_srs).



iceDice wrote:
Hello,

I have problems to show data from MySQL db on map.

I try to do that on following way:

Map params = new HashMap();
params.put("dbtype", "mysql");
params.put("host", "localhost");
params.put("port", new Integer(3306));
params.put("database", "my_db");
params.put("user", "root");

MySQLDataStoreFactory mySQLFactory = new MySQLDataStoreFactory();
MySQLDataStore mySQLDatastore = (MySQLDataStore) mySQLFactory.createDataStore(params);
// Prepare feature sources
fsStreets = mySQLDatastore.getFeatureSource("streets");

When i tried to display layer on JMapFrame i can't see anything. Values for map bounds in JMapFrame
Status bar (min and max Lat and Lon) are all NaN.

I check ogrinfo MySQL:my_db,user=root streets -so and get:
INFO: Open of `MySQL:my_db,user=root' using driver `MySQL' successful.
Layer name: streets
Geometry: Line String
Feature Count: 930
Extent: (19.559141, 46.026719) - (19.801404, 46.168960)
Layer SRS WKT:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.01745329251994328,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]
FID Column = OGR_FID
Geometry Column = SHAPE
name: String (254.0)
oneway: String (254.0)
type: String (1.0)

What can be problem here? I make table in MySQL from shapefile without .prj file with
following command: ogr2ogr -f "MySQL" MYSQL:"my_db,host=localhost,user=root,port=3306" -nln "streets" -a_srs "EPSG:4326" streets.shp

Also i try all of this with Postgis and everything works perfect.

I hope so someone can help me about this.

Best regards
iceDice

Re: GeoTools+MySQL

Reply Threaded More More options
Print post
Permalink
Hello,

I also get map from MySQL db displayed by uDig, but still can't do that with GeoTools.

I load street features in MySQLDataStore without problems but i get null for crs = fsStreets.getSchema().getCoordinateReferenceSystem().
I checked spatial_ref_sys table in MySQL and there is valid definition of geographic
coordinate system with datum, prime meridian, unit etc. I also checked in geometry_columns
table in MySQL db and my street table have SRID that correspond to geographic coordinate
system in spatial_ref_sys table. I guess that fsStreets.getSchema().getCoordinateReferenceSystem()
shouldn't return null?
I also try to force coordinate reference system to both WGS84 and CARTESIAN_2D as:
  if (crs == null) {
    crs = DefaultGeographicCRS.WGS84;
    //crs = DefaultEngineeringCRS.CARTESIAN_2D;
  }
  final MapContext map = new DefaultMapContext(crs);
  map.addLayer(new DefaultMapLayer(fsStreets, streetsStyle));

but can't get features on map.
I am only managed to get this layer from mysql in context of other layers added from
Postgis or directly from shapefile.

Can anyone help me about this. I don't know is problem in gt-mysql module or
maybe i am doing something wrong.

Thanks.



iceDice wrote:
Hello again,

I have made additional testing and i have following situation:

When i add some layers from other data sources (shapefiles, postgres)
and then add layer from mysql db i got all data displayed, but zoomed to
layer from shapefile or postgres. But when i load only data from mysql i
can't see anything. It seems to me that map bounds cannot be determined
at all when using only mysql. I don't know what i am doing wrong, i use ogr2ogr
to transform data from shapefile to mysql with option to keep CRS (-s_srs).



iceDice wrote:
Hello,

I have problems to show data from MySQL db on map.

I try to do that on following way:

Map params = new HashMap();
params.put("dbtype", "mysql");
params.put("host", "localhost");
params.put("port", new Integer(3306));
params.put("database", "my_db");
params.put("user", "root");

MySQLDataStoreFactory mySQLFactory = new MySQLDataStoreFactory();
MySQLDataStore mySQLDatastore = (MySQLDataStore) mySQLFactory.createDataStore(params);
// Prepare feature sources
fsStreets = mySQLDatastore.getFeatureSource("streets");

When i tried to display layer on JMapFrame i can't see anything. Values for map bounds in JMapFrame
Status bar (min and max Lat and Lon) are all NaN.

I check ogrinfo MySQL:my_db,user=root streets -so and get:
INFO: Open of `MySQL:my_db,user=root' using driver `MySQL' successful.
Layer name: streets
Geometry: Line String
Feature Count: 930
Extent: (19.559141, 46.026719) - (19.801404, 46.168960)
Layer SRS WKT:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.01745329251994328,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]
FID Column = OGR_FID
Geometry Column = SHAPE
name: String (254.0)
oneway: String (254.0)
type: String (1.0)

What can be problem here? I make table in MySQL from shapefile without .prj file with
following command: ogr2ogr -f "MySQL" MYSQL:"my_db,host=localhost,user=root,port=3306" -nln "streets" -a_srs "EPSG:4326" streets.shp

Also i try all of this with Postgis and everything works perfect.

I hope so someone can help me about this.

Best regards
Jody Garnett-2

Re: GeoTools+MySQL

Reply Threaded More More options
Print post
Permalink
On Tue, Sep 29, 2009 at 7:15 PM, iceDice <[hidden email]> wrote:
>
> Hello,
>
> I also get map from MySQL db displayed by uDig, but still can't do that with
> GeoTools.

uDig was using an older version of the MySQL datastore; so you may of
caught a regression.
Can I ask you to try uDig 1.2-M7 please?

Jody

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
iceDice

Re: GeoTools+MySQL

Reply Threaded More More options
Print post
Permalink
Hi Jody,

I downloaded udig-1.2-M7.linux.gtk.x86.zip and unpack them.
I tried to run udig.sh script on Linux uBuntu but i got error:
./udig.sh: 30: ./bin: not found
Then i change line:
$PRGDIR/bin -data ~/uDigWorkspace $@ in script to:
$PRGDIR/udig_internal -data ~/uDigWorkspace $@ and get uDig running.

However when i try to add layer from MySQL i succeed to connect to mysql
and get list of all databases. However i can't see any tables.
I tried same for Postgis and result is same.
I can't see any exceptions in console, however i can't get tables.
I load shapefile from file with success.

Best regards.


Jody Garnett-2 wrote:
On Tue, Sep 29, 2009 at 7:15 PM, iceDice <nmilasinovic@gmail.com> wrote:
>
> Hello,
>
> I also get map from MySQL db displayed by uDig, but still can't do that with
> GeoTools.

uDig was using an older version of the MySQL datastore; so you may of
caught a regression.
Can I ask you to try uDig 1.2-M7 please?

Jody

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users