| 1 | = shapefileObj = |
| 2 | |
| 3 | {{{ |
| 4 | #!perl |
| 5 | $shapefile = new mapscript::shapefileObj('lakes',-1) or die "Unable to open lakes shapefile"; |
| 6 | |
| 7 | $extents = $shapefile->{bounds}; |
| 8 | |
| 9 | $numshapes = $shapefile->{numshapes}; |
| 10 | |
| 11 | $typeno = $shapefile->{type}; |
| 12 | |
| 13 | $shapefile->add($shape); |
| 14 | |
| 15 | This example saves a selected polygon shape into a new shapefile. |
| 16 | # |
| 17 | # Open the map. |
| 18 | my $map = new mapscript::mapObj('your.map'); |
| 19 | # |
| 20 | # Create the layer object to query. |
| 21 | my $layer = new mapscript::layerObj($map); |
| 22 | # |
| 23 | # Create a new shapefile for the selection set. |
| 24 | my $newshpf = new mapscript::shapefileObj("$newshpfname", $mapscript::MS_SHAPEFILE_POLYGON); |
| 25 | # |
| 26 | # Set index value for selected shape. |
| 27 | my $poly = 400; |
| 28 | # |
| 29 | # Create a shapefile object for getting queried shape. |
| 30 | my $shpf = new mapscript::shapefileObj("data_shapefile", -1); |
| 31 | # |
| 32 | # Create shape object for storing queried shape. |
| 33 | my $shp = new mapscript::shapeObj(-1); |
| 34 | # |
| 35 | # Retrieve shape into shape object. |
| 36 | $shpf->get($poly, $shp); |
| 37 | # |
| 38 | # Put shape into new shapefile. |
| 39 | $newshpf->add($shp); |
| 40 | # |
| 41 | # Create dbf to go with new. |
| 42 | @toucherror = system("touch $newshpfname.dbf"); |
| 43 | # |
| 44 | # Get the extent of the new shapefile. |
| 45 | my $newrect = $newshpf->{bounds}; |
| 46 | my $newminx = $newrect->{minx}; |
| 47 | my $newminy = $newrect->{miny}; |
| 48 | my $newmaxx = $newrect->{maxx}; |
| 49 | my $newmaxy = $newrect->{maxy}; |
| 50 | # |
| 51 | # Close new shapefile. |
| 52 | undef $newshpf; |
| 53 | }}} |
| 54 | ---- |
| 55 | back to PerlMapScript |