[OSM-talk] Osmosis and .shp files
Frederik Ramm
frederik at remote.org
Tue Dec 25 23:06:05 GMT 2007
Hi,
> I recently took one of their Arc/INFO files and edited it to suit in qgis. I
> now have ARC.shp that reflects the area I want to feed into Osmosis. Can
> anyone recommend a way of converting that into the required polygon-bounding
> format for Osmosis?
The script below is suitable for grabbing any number of shapes from a
shapefile and writing them out as .poly files. Requires some tweaking
probably.
Bye
Frederik
#!/usr/bin/perl
use Geo::ShapeFile;
my $shapefile = new Geo::ShapeFile("my.shp");
# the first for loop runs through all shapes in the file and looks
# at their db entries; if they are "wanted", they are added to a list.
# each list created here will lead to one .poly file later. multiple
# shapes can be pushed onto the same list.
# IF YOUR INPUT CONTAINS JUST ONE SHAPE AND YOU SIMPLY WANT A
# POLY FILE FROM IT:
# replace the whole "for" loop by
# $shapes{"out"} = 1..$shapefile->shapes();
for (1..$shapefile->shapes ())
{
my %db = $shapefile->get_dbf_record ($_);
if ($db{"this"} eq "that") # test if the shape is wanted
{
push (@{$shapes{"shapename"}}, $_); # record shape on a stack
# named "shapename" (will lead to shapename.poly later)
}
}
# second loop writes the actual shape info into polygon files
foreach my $shpkey (keys(%shapes))
{
open (B, ">$shpkey.poly");
print B "$shpkey\n";
my $cnt=1;
foreach my $shapeid(@{$shapes{$shpkey}})
{
my $shape = $shapefile->get_shp_record ($shapeid);
for(1 .. $shape->num_parts)
{
my @part = $shape->get_part($_);
my @polypoints;
printf B "%d\n", $cnt++;
foreach my $pt(@part)
{
printf B " %E %E\n", $pt->X(), $pt->Y();
}
print B "END\n";
}
}
print B "END\n";
close(B);
}
More information about the talk
mailing list