Changes between Initial Version and Version 1 of MySQL


Ignore:
Timestamp:
Jan 28, 2009, 1:01:47 PM (15 years ago)
Author:
jmckenna
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MySQL

    v1 v1  
     1= MySQL Access =
     2
     3----
     4The official MySQL with MapServer doc lives at: http://www.mapserver.org/input/vector/mysql.html
     5----
     6
     7This page should provide information about using data sources from a non-spatially enabled MySQL server. It should work with both 3.x and 4.x versions of MySQL. If you have any questions or suggestions, contact the author (AttilaCsipa).
     8
     9Using a mysql data source means that BOTH spatial and feature data are stored in mysql tables. If you want shapefiles (.SHP) for spatial data and mysql for feature data (usually stored in the .DBF files), you might want to take a look at JoinDatasources
     10
     11== Installing ==
     12
     13   1. Get the source from CVS.
     14   2. Get Shapelib (http://www.cpan.org/modules/by-module/Geo/ -> Geo-Shapelib-X)
     15
     16   1. Make sure you have mysql server and client libraries installed (you might also need the mysql-dev packages to compile), and that their version matches.
     17   2. Do everything as in a regular build but add the '--with-mygis' when doing ./configure
     18   3. Convert your existing data (.SHP files, .DXF, MapInfo, etc.) source to OpenGIS Simple Features compliant database in mysql
     19   4. Change .map file(s) to suit the new data sources
     20
     21== Converting SHP data into MySQL based OpenGIS SFSQL ==
     22
     23The easiest way to do this is to use the shp2mysql.pl perl script supplied with MapServer (if you do not have it, chances are that you are not using a recent and complete version). To use this conversion script you MUST install the perl binding for shapelib (http://www.water.hut.fi/pub/Grid/Shape-0.04.tar.gz). First, you have to edit the database access parameters in the shp2mysql file itself. After that, simply type
     24{{{
     25 shp2mysql.pl /path/to/shp/file/my_shape_file
     26}}}
     27to convert the shape file as a new layer. If all goes well, you should see a progress indicator and after a while the shape file will be converted. You should repeat this step for all shape files/layers you wish to use.
     28
     29The converter will also automatically convert all data from .dbf files to the MySQL database's feature table, but note that the fields will be prefixed with "f_" to avoid name collisions with existing data columns. Thus, if you have a 'color' field, it will become 'f_color'.
     30
     31== Altering the .map file to use sql data sources ==
     32
     33In the .map file use the following syntax (use 'bin' or 'num' in the last field depending on stored data type - binary or numerical):
     34{{{
     35 LAYER
     36  CONNECTIONTYPE mygis
     37  NAME "Telefon"
     38  CONNECTION "hostname:user:password:database:bin:"
     39  DATA "geometry from TELEFON_LINE feature, TELEFON_LINE_bin geometry"
     40  FILTER "feature.myattrib=22"
     41  STATUS ON
     42  TYPE LINE
     43  CLASS
     44    COLOR 55 65 0
     45  END
     46 END
     47}}}
     48In this example, hostname, user, password and database specify the connection parameters to the MySQL database. Do not forget to add bin: to the end of the string (This specifies binary data access) ! The two tables used in the above example are thus TELEFON_LINE and TELEFON_LINE_bin. Same thing for an annotation layer but note that the labelitem and classitems are columns of the feature table !
     49{{{
     50 LAYER
     51  CONNECTIONTYPE mygis
     52  CONNECTION "host:user:password:database:bin:"
     53  DATA "geometry from TEKSTULICE_TEXT feature, TEKSTULICE_TEXT_bin geometry"
     54  NAME "tekstulice"
     55  STATUS ON
     56  TYPE ANNOTATION
     57  LABELITEM "txt"
     58  CLASSITEM "angle"
     59  LABELANGLEITEM "angle"
     60  CLASS
     61    COLOR -1 -1 -1
     62    LABEL
     63      COLOR 6 6 24
     64      SHADOWCOLOR -1 38 38
     65      SHADOWSIZE 1 1
     66      TYPE TRUETYPE
     67      FONT verdana
     68      SIZE 10
     69      POSITION CC
     70      PARTIALS FALSE
     71      BUFFER 2
     72    END
     73  END
     74 END
     75}}}
     76That's it, all the other MapServer features can be used in conjuction with this.
     77
     78== FAQ ==
     79
     80=== How does this work ? ===
     81
     82Through a dedicated MapServer module written in C.
     83
     84=== How do I use it ? ===
     85
     86See the Installing chapter above.
     87
     88=== I tried that, but configure says there is no such option ! ===
     89
     90Make sure you have a recent version of Mapserver. The MyGIS? module has been added on 2003. 03. 15. in version 3.7
     91
     92Mapserver dies with the following - Warning: [MapServer Error]: msMYGISLayerOpen?(): msMYGISLayerOpen? called but unimplemented! mapserver not compiled with MYGIS support)
     93
     94As it says, you have not compiled MYGIS support. Currently NONE of the binary distributions come with MYGIS in them, you HAVE to compile it yourself.
     95
     96=== I have downloaded the windows version and it does not work ===
     97
     98If you downloaded the windows binary (in fact, any binary) chances are that it was not compiled with mysql support.
     99
     100=== I have MySQL 4.x installed and the compile fails, or Mapserver dies randomly ===
     101
     102Get the newest version from CVS, these problems have been addressed
     103
     104=== There is no shp2mysql.pl file in my Mapserver distribution ! ===
     105
     106Get the newest version from CVS.
     107
     108=== How do I convert my shapefile data to mysql ? ===
     109
     110See 'converting .shp files' in the installchapter.
     111
     112=== Fields I had in my SHP files are lost ! ===
     113
     114Not lost, but renamed. All field names are prefixed with "f_" to avoid name collisions with existing columns. If you are unsure what you have in the database you can always do an 'EXPLAIN [FEATURE_TABLE]' to see the columns/fields available.
     115
     116=== What is the data format used for storage ? ===
     117
     118The data is encoded in a format called OpenGIS Simple Feature format, though it is not (yet) fully compliant. It supports both numerical and binary (WKB) storage types in little and big endian encodings.
     119
     120=== I have a Mac and Mapserver times out (or takes very long time to load, why is that ? ===
     121
     122The module converts between little-endian and big-endian (PC and Mac) data transparently. However, this conversion is VERY slow in any real world application. The solution is to use a data set which is in a native format and thus needs no conversion.
     123
     124=== The query faild but no error message is given ! ===
     125
     126In some cases debugging is hard, indeed. Your best bet is to turn on mysql logging (usually in mysql.ini) and then check mysql.log to see the complete and exact query that fails.
     127
     128=== Why use MySQL instead of postgis + postgreSQL (or eventually postgis + MySQL when it becomes available) ? ===
     129
     130Stored procedures (which will be used by postgis) will appear in mysql 4.1 at the earliest, but it looks like this particular feature may slip to even later, since it recently disappeared from the 4.1 features list (but this might be an error in the list itself, tho, I'm not on the mysql dev lists). Second, maybe even more important that this is NOT a mysql implementation of postgis, but rather a separate approach. As you maybe noticed my connector implementation is based on almost pure ansi sql, so with minimal changes it can be used practically with ANY sql database. It IS slower than postgis, but even with postgis-mysql 4.1 available, this solution is an option because it does not require to jump on a relatively unstable new mysql, does not require to install postgis if you do not already have it and, finally, it does not require additional knowledge beside plain sql to use and modify. So basically it is a 'sql-lite' connector - compatible with practically everything and easy to use, the downside being slower than a regular postgis approach.
     131
     132=== I heard the mapMyGIS? module does not work with MySQL 4.0 ? ===
     133
     134CVS builds after 22.01.2004 should work just fine with all 3.x and 4.x versions of MySQL
     135
     136== Known limitations ==
     137
     138If you are NOT using shp2mysql, please note that
     139
     140   1. OpenGIS data in binary format must be stored as GEOMETRY_COLLECTION
     141   2. OpenGIS data in numerical format must have 2 dimensions/points per entry (but entries can be constructed from multiple items that have 2 points, even complex polygons !)
     142   3. Untested under Windows
     143
     144Other than that
     145
     146   1. Slow
     147   2. Buggy
     148
     149== Required shp2mysql.pl edits ==
     150{{{
     151use Shape qw/:all/; becomes Use Geo::Shapelib qw/:all/;
     152
     153$shape = new Shape $ARGV[0]; becomes $shape = new Geo::Shapelib $ARGV[0];
     154}}}
     155
     156== Windows HOWTO ==
     157If you have any questions or suggestions for the Windows HOWTO, contact (BartVanDenEijnden).
     158
     159   1. Install ActiveState Perl (http://www.activestate.com/Products/Download/Register.plex?id=ActivePerl). I use version 5.8.0.804.
     160   2. Install the ppm for DBI from http://ppm.activestate.com/PPMPackages/zips/8xx-builds-only/Windows/DBI.zip, followed by "ppm install DBI.ppd" in a DOS prompt
     161   3. Install Shapelib from http://www.cpan.org/modules/by-module/Geo/Geo-Shapelib-0.06.tar.gz, here comes the trouble, there is no ppm for Geo-Shapelib, only for Geo-Shapefile.