[Mapserver-users] Perl Mapscript - render shapefile with no m ap

Sean Gillies sgillies at frii.com
Tue Mar 11 11:27:04 EST 2003


Andrew,

With mapscript you can create a empty map object, add a layer to it,
define data, add a class and draw the map.  Is that what you're
looking for?  Something like this (some corrections to my Perl
syntax may be necessary):

use mapscript;

# Create empty map object, no file needed
$map = new mapscript::mapObj("");

# Set map properties, extents, imagecolor etc
$map->{extent}->{minx} = 0.0;
...
$map->{imagecolor}->{red} = 153;
...
$map->setImagetype("png");

# Create new layer
$layer = new mapscript::layerObj($map);

# Set layer attributes, name, status, data etc
$layer->name = "Foo";
$layer->status = $mapscript::MS_DEFAULT;
$layer->type = $mapscript::MS_POLYGON;
$layer->data = "/tmp/foo.shp";
...

# Define a class for this layer
$class = new mapscript::mapObj($layer);

# Set class attributes
$class->{color}->{red} = 255;
...
$class->{outlinecolor}->{red} = 0;
...

# Draw
$img = $map->draw();

# Save image to a file
$img->saveImage("/tmp/foo.png", $mapscript::MS_PNG, 0, 0, 0);

I'm leaving out a bunch of necessary attributes, but you should get
the picture.

hope this helps,
Sean

On Tuesday, March 11, 2003, at 08:58  AM, Simpson, Andrew wrote:

>
> What I'd like to do is render a map using Perl mapscript only, without
> static or dynamic map files, and without stepping through the shapes.
> I know I should just go with one of these two work arounds, but the 
> code to
> do this seems to be available and I would like to avoid the overhead of
> creating/deleting map files.
>
> Thanks for your reply,
> Drew.
>
> P.S. Sorry for the double post, I had E-Mail alias problems.
>
> -----Original Message-----
> From: Lowell Filak [mailto:lfilak at medinaco.org]
> Sent: Tuesday, March 11, 2003 8:54 AM
> To: Simpson, Andrew; 'mapserver-users at lists.gis.umn.edu'
> Subject: Re: [Mapserver-users] Perl Mapscript - render shapefile with 
> no
> map
>
>
> I may be missing the question but:
> What you are trying to do does work.
> If you dynamically create a mapfile and include a 'place-holder' layer
> definition and then set the $layer->{data} on the fly it does work.
> Being that you are trying to set the $layer->{data} dynamically does 
> that
> mean you are trying to set the 'data' to a shapefile that was just 
> created?
> If so you will want to make sure that the data.shp has a corresponding
> data.dbf file to go with it or the $layer->{data} = 'data' will fail.
> HTH
> Lowell F.
>
> The following message was sent by "Simpson, Andrew"
> <Andrew.Simpson at ssc.nasa.gov> on Mon, 10 Mar 2003 16:22:24 -0600.
>
>> Greetings,
>>
>> Has anyone had any success rendering a map using Perl mapscript and a
>> shapefile with no map file and without having to open the shapefile 
>> and
> step
>> through and draw every shape.
>> I have had success instantiating a map object with dynamically 
>> generated
> map
>> files.
>> I have also had success manually opening the shapefile and iterating
> through
>> the shapes rendering each, but this is cumbersome and does not take
>> advantage of tiling.
>> I have not been able render a map by just setting the layer->{data}
>> attribute to a shapefile.
>> Is this possible?
>>
>> Thanks for any help,
>> Drew.
>>
>>
>>
>>
>
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>




More information about the mapserver-users mailing list