[non-spatial]-mysql: point data source

Roberto Bianconi rbianconi at ENVIROWARE.COM
Wed Dec 29 05:04:21 EST 2004


Hi,

these could be some hints (i.e. won't run as it is) to create the layer with the points, using Perl.
I think you can grab the ideas and implement it into Php, if it is what you need.


# load mapscript and XBase modules

use mapscript;
use XBase;

# Set the path and name to the shapefile you'll create

my $basename = 'path_to_filename'

# Create the new shapefile

my $shapefile = new mapscript::shapefileObj("$basename", 1) or die;

# Create the new DBF table

my $table = XBase->create("name" => $basename,
                          "field_names" => ["X", "Y", "ATTRIBUTE_1", "ATTRIBUTE_2"],
                          "field_types" => ["N", "N", "C", "C"],
                          "field_lengths" => [8, 8, 50, 2],
                          "field_decimals" => [4, 4, 0, 0) or die;

# Create a new pointObj
my $point = new mapscript::pointObj();

# Assuming you connect to the MySQL database to get the data (use DBI and DBD modules to do that,
# and standard SQL syntax) you loop on table records or store them into hashes or arrays, and for
# each record you set

        $point->{x} = $x;
        $point->{y} = $y;
        $shapefile->addPoint($point);

        # Then you fill the DBF record ($i is the loop index)

        $table->set_record($i, $x, $y, $attribute_1, $attribute_2);

# When you're done with the loop on your points, close the DBF

$table->close();
undef $shapefile;


Hope this helps.
Roberto

------------------------------------------------
ENVIROWARE SRL
Centro Direzionale Colleoni, Palazzo Andromeda 1
I-20041 Agrate Brianza (MI) - Italy

T:++39 039 6890073 / F:++39 039 6881459
mailto:rbianconi at enviroware.com
http://www.enviroware.com
------------------------------------------------

On Tue, 27 Dec 2004, Dylan Beaudette wrote:

> Greetings everyone!
>
> I have been using mapserver for quite some time with shapefiles, and am
> quite pleased with its flexibility.
>
> I was wondering if it would be possible to add point data records, stored
> in a MySQL data base, to a map that was created by shapefiles. The records
> in mysql would be formatted as follows:
>
> point_id, x, y, attribute_1, ...
>
> this is not in the openGIS format that the myGIS connector is using, and
> so I wonder if it is even possible to get a 'list' of points like this
> into a mapserver application.
>
> I would like to use PHPmapscript, but i have problems running PHP as a CGI
> as opposed to the more traditional Apache DSO (maybe this problem has been
> solved...)
>
> any ideas would be greatly appreciated.
>
> Dylan
>



More information about the mapserver-users mailing list