Hi there
does anyone have experience with creating .poly files (those used with osmosis) ?
all the sources of polygon files out there are not suitable enough for me. i want to do it by myself, but creating it manually is really annoying and time consuming. :-(
simple "by-mouse click-clack way" graphical tool is prefered. (if you know what i mean ... nak-nak)
any ideas are welcome
*EDIT: renamed subject from [wanted] to [TOOL]
josm
Sent from my Galaxy Nexus using Tapatalk 2
thanks for quick reply.
anyway... in the meanwhile i have found a nice way how to do that easily enough ;-)
- maps.google.com
- create new map
- draw a line
- save
- reopen map
- download kml file
- edit a bit to match .poly file syntax
done
Hello Jurajs,
Im finally here on Locus-Forum, is ways more responsive than Mapsforge-Dev and I hate GoogleGroups :-)
For you Toppic: I create polys as tracks in TTQV (any other MappingTool is possible) and export the tracks as gpx.
I wrote/modified two perlscripts to convert poly2gp and vice-versa.
The gpx2poly script has an additional feature for MapsforgeWriter, it writes a .bat file with the parameters (bbox!!) used for creating the map fitting the borders of the poly-file. The paths are fixed coded for my folder structure but its a matter of a few minutes to adjust this to your needs.
poly2gpx.pl:
#!/usr/bin/perl -w
#
# poly2gpx.pl - convert a polygon file to GPX
#
# see http://wiki.openstreetmap.org/wiki/Osmosis/Polygon_Filter_File_Format
# for the format of the polygon files
#
# Author: Hanno Hecker <vetinari+osm@ankh-morp.org>
#
# modified for windows (direct input/output from/to file - no more hassle with pipelines)
# made code more readable, this adds some milliseonds to processing time ;-)
# by Christian Kernbeis 2012
#
# Licence: GPL v3.0
# Version: 0.4.1
#
# usage: poly2gpx.pl [filename] WITHOUT EXTENSION
# eg: poly2gpx.pl austria = OK
# poly2gpx.pl austria.poly = WRONG !!!
#
############################################################################################
use strict;
use Math::Polygon;
use Carp qw( croak );
use Getopt::Long;
my $VERSION = "0.4.1";
my $name = undef;
my $trans = undef;
my $use_name = 0;
my $polyname = shift;
my $infile = $polyname.".poly";
my $outfile = $polyname.".gpx";
my @nodes = ();
my $line;
my @infile;
my $trkseg = 0;
my $trknum = 0;
#read infile to array
open (IN,"<",$infile) || die("Could not open $infile ...");
while ($line = <IN>){
#print $line; # for testing only
push (@infile, $line);
}
close (IN);
open (out1,">",$outfile) || die("Could not open $outfile ...");
print out1 <<__END;
<?xml version='1.0' encoding='UTF-8'?>
<gpx version="1.1" generator="poly2gpx.pl v$VERSION"
xmlns="http://www.topografix.com/GPX/1/1">
<metadata>
<name></name>
<desc></desc>
<author>
<name></name>
<email domain="" id=""/>
</author>
<copyright author="">
<year></year>
<license></license>
</copyright>
</metadata>
__END
foreach $line (@infile) {
if ($line =~ /^s*!?(d+)s*$/) {
$trknum = $1;
print out1 " <trk>n",
" <trkseg>n";
$trkseg = 1;
}
elsif ($line =~ /^s*ENDs*$/) {
if ($trkseg) {
$trkseg = 0;
$trknum = 0;
print out1 " </trkseg>n </trk>n";
}
else {
if ($use_name and defined $name) {
if ($trans) {
eval $trans;
if ($@) {
warn "WARNING: transformation of $name failed: $@n";
}
}
if ($nodes[0][0] != $nodes[-1][0] and $nodes[0][1] != $nodes[-1][1]) {
push @nodes, $nodes[0];
warn "WARNING: polygon '$name' is not closed...n";
}
my $poly = Math::Polygon->new(@nodes);
my $lat_lon = eval { $poly->centroid; }; # see below
if ($@) { warn $@; } # ... not here, at the end of the file
else {
#$name = encode_entities_numeric($name);
$name =~ s/&/&/g;
$name =~ s/</</g;
$name =~ s/>/>/g;
printf out1 " <wpt lat="%.7f" lon="%.7f">n <name>%s</name>n </wpt>n",
@{ $lat_lon }, $name;
}
}
print out1 "</gpx>n";
}
}
elsif ($line =~ /^s+([-+d.Ee]+)s+([-+d.Ee]+)s*$/) {
printf out1 " <trkpt lat="%.7f" lon="%.7f"/>n", $2, $1;
push @nodes, [$2, $1]
if $use_name and $trknum == 1;
}
elsif ($line =~ /^(S+)/ and not defined $name) {
$name = $1
if $1 ne "polygon";
}
}
close (out1);
print "### DONE ###";
gpx2poly.pl
#!/usr/bin/perl
# script to convert a GPX file to a polygon file.
#
# written by Rodolphe QuiƩdeville <rodolphe@quiedeville.org>, GPL.
#
# Modified for better usability = no more ">" "|", direct file output
# so it's suitable for Windows environment and so on ....
# ensured compatibility with "GPX10" output of tracks from QuoVadis6.0
#
# by Christian Kernbeis 2012, GPL
#
# Scipt have to be started in the directory of th gpx-file !!
#
# usage: eg given file = austria.gpx
# call = gpx2poly.pl austria
# output is written to austria.poly
# + map_austria.bat = batch for creating mapsforge map with bbox parameters
use strict;
my $infile = shift;
my $poly_id = 0;
my $poly_file;
my $polybuf;
my $outbuf;
my $id=0;
my $fh;
my $line;
my $inextension = "gpx";
my $outextension = "poly";
my $infilestring = "\maps\osm_data\my_clipbounds\europe\".$infile.".".$inextension;
my $outfilestring = "\maps\osm_data\my_clipbounds\europe\".$infile.".".$outextension;
my $bboxfile = "map_".$infile.".bat";
my @latbuff;
my @lonbuff;
my $bbox;
my $min_lat;
my $max_lat;
my $min_lon;
my $max_lon;
#open file
open (fh, $infilestring) or die $!;
while($line = <fh>)
{
if ($line =~ /^s*<trkpt.*slat=["']([0-9.eE-]+)["'] lon=["']([0-9.eE-]+)["']/){
$polybuf .= sprintf "t%ft%fn", $2,$1;
push (@lonbuff, $2);
push (@latbuff, $1);
}
elsif ($line =~ /^s*<trk>/){
$polybuf = "";
$poly_id++;
}
elsif ($line =~ /^s*</trk>/){
$outbuf .= "$poly_idn$polybuf"."ENDn";
}
}
close (fh);
open (fh,">",$outfilestring) or die $!;
print fh "$infilen$outbuf"."ENDn";
close fh;
@latbuff = sort { $a <=> $b } @latbuff;
@lonbuff = sort { $a <=> $b } @lonbuff;
$min_lat = @latbuff[0] - 0.0005; #runden auf 3 stellen genau FLOOR
$min_lon = @lonbuff[0] - 0.0005;
@latbuff = reverse sort { $a <=> $b } @latbuff;
@lonbuff = reverse sort { $a <=> $b } @lonbuff;
$max_lat = @latbuff[0] + 0.0005; #runden auf 3 stellen genau CEIL
$max_lon = @lonbuff[0] + 0.0005;
$bbox=
"bbox="
.sprintf ("%.3f",$min_lat)
.","
.sprintf ("%.3f",$min_lon)
.","
.sprintf ("%.3f",$max_lat)
.","
.sprintf ("%.3f",$max_lon);
open (fh,">",$bboxfile) or die $!;
print fh "d:\maps\osmosis\bin\osmosis_e.bat --rb file=D:\maps\Mapsforge\$infile\$infile","_merged.osm.pbf --mw file=D:\maps\Mapsforge\$infile\$infile.map $bbox tag-conf-file=D:\maps\Mapsforge\tag-mapping-cycle.xml bbox-enlargement=5nexitn";
close fh;
print "$bbox";
The scripts are running both on ActivePerl and StrawberryPerl for Windows and should be copied as usual to perlperlsitebin
regards
Christian
Hi Christian,
Glad to see you here ;-) I am sure indeed that your input will be valuable here.
I have already some perl scrips to convert gpx to poly, but as far i need to have .poly files as simple as possible, the way with gmaps along with editing kml to poly is sufficient and comfortable enough for my purpose ;-) thanks anyway.
p.s. welcome to locus community ;-)