Skip to content

Commit

Permalink
Merge pull request #27 from taranarmo/master
Browse files Browse the repository at this point in the history
Switch to Python 3
  • Loading branch information
jonasstein authored Apr 2, 2023
2 parents 6a47a2a + e4a91cb commit 72e8f61
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 145 deletions.
184 changes: 92 additions & 92 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
* scanaerial
- Scan for areas of similar colour on aerial pictures like OCR for text.
- recognition works well with lakes, however it will not produce good results with
wood in near future.
* Features/Changelog
** 2.1-beta-1
- Bing support merged in. Thanks to Cybjit and IrlJidel
- Improved TMS support ({-y} and {switch:} options added)
- Timeout check replaced by size limit feature: now it is possible to trace rivers
- Tags settings moved to configuration file
- Fixed bugs in Douglas-Peucker algorithm
- Detection of empty tiles added
** 2.0-beta.1
- TMS support added, new timeout check. Thanks to Vort
** 1.0.3
- malenki et al. reported that latlon.org does not work at the moment/anymore (?)
geoposer.com is another bing WMS server, but somone has to figure out how to use it with scanaerial.
Till then it is possible to use landsat with
wms_server_url = http://irs.gis-lab.info/?layers=landsat&
** 1.0.2
- added tag source:zoomlevel. You see sometimes very different details
in different zoomlevels.
** 1.0.1
- inner and outer Multipolygon work
** 1.0.0
- TMS Zoomlevel of JOSM is used for the downloaded WMS Tiles
- scanaerial works with Ext_tools Plugin
* Requirements
- JOSM
- Python. You can run library_check.py to find out if a library is missing
- Ext_tools plug-in for JOSM.
{TZoom} is part of Ext_tools since Ext_tools 25274
- Of course you need the scanaerial files too.
You will find the latest releases on
[[https://github.com/jonasstein/scanaerial/archives/master]]
Copy them to JOSM/plugins/scanaerial for example.
* Setup
- unzip the contents of the downloaded archive to the JOSM plugin directory
Linux users put it to: ~/.josm/plugins/ext_tools/scanaerial
- start JOSM, press F12 and go to Ext_tools configuration
- use this cmdline:/home/<username>/.josm/plugins/ext_tools/scanaerial/scanaerial.py {lat} {lon} {TZoom}
It will create a new menu item in JOSM. (NB: Syntax may change soon)
Due to a bug in Ext_tools you can not write "~" instead of "home"
- For best result you may finetune the values in scanaerial.cfg
| key | function |
|-------------------------+-----------------------------------------------------------|
| fixedzoomlevel | use this zoomlevel, if Ext_tools did not tell via TZoom |
| server_api | access method of map server: wms, tms or bing |
| server_name | name of the map server (only for the tag string) |
| server_url | half-link for WMS, JOSM-like address for TMS |
| empty_tile_bytes | size of empty tile (in bytes) for current map server |
| empty_tile_checksum | checksum of empty tile file (algorithm: CRC32) |
| projection | projection that is used on the map server |
| tile_sizex,-y | leave it to 256 unless you know what you do |
| douglas_peucker_epsilon | maximum roughness for smoothening the line |
| deactivate_simplifying | deactivate Douglas-Peucker algorithm (only for debugging) |
| colour_str | colour sensitivity (depends on contrast of images) |
| maxfilter_setting | median filter size (noise reduction strength) |
| size_limit | maximum size of produced object |
* Roadmap
- collect recipies for better algorithms
- try to exclude douglas-peucker from scanaerial. josm can do that.
- try different algorithms in forks and compare them.
- try to access cached wms tiles from josm
- rewrite in c(++) and/or java
- find betatester
* Troubleshooting
- if anything fails have a look on the error console.
Scanaerial is very verbous.
* Found a bug?
- [[https://github.com/jonasstein/scanaerial/issues]]
- if you want to contribute, please
make a fork,
make your changes in the fork
do a pull request on this project site, or contact the author
* Links
- [[http://wiki.openstreetmap.org/wiki/Scanaerial][OSM Wiki about scanaerial]]
* Have fun!
* scanaerial
- Scan for areas of similar colour on aerial pictures like OCR for text.
- recognition works well with lakes, however it will not produce good results with
wood in near future.

* Features/Changelog

** 2.1-beta-1
- Bing support merged in. Thanks to Cybjit and IrlJidel
- Improved TMS support ({-y} and {switch:} options added)
- Timeout check replaced by size limit feature: now it is possible to trace rivers
- Tags settings moved to configuration file
- Fixed bugs in Douglas-Peucker algorithm
- Detection of empty tiles added

** 2.0-beta.1
- TMS support added, new timeout check. Thanks to Vort

** 1.0.3
- malenki et al. reported that latlon.org does not work at the moment/anymore (?)
geoposer.com is another bing WMS server, but somone has to figure out how to use it with scanaerial.
Till then it is possible to use landsat with
wms_server_url = http://irs.gis-lab.info/?layers=landsat&

** 1.0.2
- added tag source:zoomlevel. You see sometimes very different details
in different zoomlevels.

** 1.0.1
- inner and outer Multipolygon work

** 1.0.0
- TMS Zoomlevel of JOSM is used for the downloaded WMS Tiles
- scanaerial works with Ext_tools Plugin

* Requirements
- JOSM
- Python. You can run library_check.py to find out if a library is missing
- Ext_tools plug-in for JOSM.
{TZoom} is part of Ext_tools since Ext_tools 25274
- Of course you need the scanaerial files too.
You will find the latest releases on
[[https://github.com/jonasstein/scanaerial/archives/master]]
Copy them to JOSM/plugins/scanaerial for example.

* Setup
- unzip the contents of the downloaded archive to the JOSM plugin directory
Linux users put it to: ~/.josm/plugins/ext_tools/scanaerial
- start JOSM, press F12 and go to Ext_tools configuration
- use this cmdline:/home/<username>/.josm/plugins/ext_tools/scanaerial/scanaerial.py {lat} {lon} {TZoom}
It will create a new menu item in JOSM. (NB: Syntax may change soon)
Due to a bug in Ext_tools you can not write "~" instead of "home"
- For best result you may finetune the values in scanaerial.cfg

| key | function |
|-------------------------+-----------------------------------------------------------|
| fixedzoomlevel | use this zoomlevel, if Ext_tools did not tell via TZoom |
| server_api | access method of map server: wms, tms or bing |
| server_name | name of the map server (only for the tag string) |
| server_url | half-link for WMS, JOSM-like address for TMS |
| empty_tile_bytes | size of empty tile (in bytes) for current map server |
| empty_tile_checksum | checksum of empty tile file (algorithm: CRC32) |
| projection | projection that is used on the map server |
| tile_sizex,-y | leave it to 256 unless you know what you do |
| douglas_peucker_epsilon | maximum roughness for smoothening the line |
| deactivate_simplifying | deactivate Douglas-Peucker algorithm (only for debugging) |
| colour_str | colour sensitivity (depends on contrast of images) |
| maxfilter_setting | median filter size (noise reduction strength) |
| size_limit | maximum size of produced object |

* Roadmap
- collect recipies for better algorithms
- try to exclude douglas-peucker from scanaerial. josm can do that.
- try different algorithms in forks and compare them.
- try to access cached wms tiles from josm
- rewrite in c(++) and/or java
- find betatester
* Troubleshooting
- if anything fails have a look on the error console.
Scanaerial is very verbous.

* Found a bug?
- [[https://github.com/jonasstein/scanaerial/issues]]
- if you want to contribute, please
make a fork,
make your changes in the fork
do a pull request on this project site, or contact the author

* Links
- [[http://wiki.openstreetmap.org/wiki/Scanaerial][OSM Wiki about scanaerial]]

* Have fun!
36 changes: 21 additions & 15 deletions canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

from __future__ import division
from future import standard_library
standard_library.install_aliases()
from builtins import str
from builtins import range
from builtins import object
if __name__ == "__main__":
exit(0)

Expand All @@ -23,22 +29,22 @@
from urllib.error import URLError
from urllib.error import HTTPError
except ImportError:
from urllib2 import urlopen
from urllib2 import URLError
from urllib2 import HTTPError
from urllib.request import urlopen
from urllib.error import URLError
from urllib.error import HTTPError
import io
import datetime
import sys
import random
import binascii
from time import clock
from time import process_time as clock
from debug import debug
#
import projections

time_str = {0:" first ", 1:" second ", 2:" third and last "}

class WmsCanvas:
class WmsCanvas(object):

def __init__(self, server_url = None, server_api = None, proj = "EPSG:4326", zoom = 4, \
tile_size = None, mode = "RGBA", empty_tile_bytes = 0, empty_tile_checksum = 0):
Expand Down Expand Up @@ -113,21 +119,21 @@ def baseN(self, num, b, numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
def ConstructQuadkey (self, tileX, tileY):
"""return Bing quadkey for given integer tile
see (http://msdn.microsoft.com/en-us/library/bb259689.aspx)"""

tileX2 = self.baseN(tileX, 2)
tileY2 = self.baseN(tileY, 2)

pad = self.zoom

tileX2 = "0"*(pad - len(tileX2)) + tileX2
tileY2 = "0"*(pad - len(tileY2)) + tileY2

quadkey2 = ""
for x in range(pad):
quadkey2 = quadkey2 + tileY2[x] + tileX2[x]

quadkey = int(quadkey2, 2)

quadkey4 = self.baseN(quadkey, 4)
quadkey4_pad = "0"*(pad - len(str(quadkey4))) + str(quadkey4)

Expand All @@ -148,7 +154,7 @@ def FetchTile(self, x, y):
for dl_retrys in range(0, 3):
try:
contents = urlopen(remote).read()

except URLError as detail:
server_error = True
debug("error while fetching tile (" + str(x) + ", " + str(y) + ": " + str(detail))
Expand Down Expand Up @@ -177,7 +183,7 @@ def FetchTile(self, x, y):
continue
dl_done = True
break

if not dl_done:
if server_error:
raise URLError(detail)
Expand All @@ -189,13 +195,13 @@ def FetchTile(self, x, y):
self.tiles[(x, y)] = {}
self.tiles[(x, y)]["im"] = tile_data
self.tiles[(x, y)]["pix"] = tile_data.load()


def PixelAs4326(self, x, y):
scale = 1.0
if (self.server_api == "tms") or (self.server_api == "bing"):
scale = 0.5
return projections.coords_by_tile(self.zoom, scale * x / self.tile_width, scale * y / self.tile_height, self.proj)
return projections.coords_by_tile(self.zoom, scale * x * 1.0 / self.tile_width, scale * y * 1.0 / self.tile_height, self.proj)

def PixelFrom4326(self, lon, lat):
scale = 1.0
Expand Down
1 change: 1 addition & 0 deletions debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

from builtins import str
if __name__ == "__main__":
exit(0)

Expand Down
36 changes: 18 additions & 18 deletions doc/README.ssm
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@

# Python ~{You can run library_check.py to find out if a library is missing}~

# Ext_tools plugin version >= 25274 for JOSM
# Ext_tools plugin version >= 25274 for JOSM

# Of course you need the scanaerial files too. You will find the latest releases on
# Of course you need the scanaerial files too. You will find the latest releases on
{ Github }https://github.com/jonasstein/scanaerial/archives/master Copy them to JOSM/plugins/scanaerial for example


:B~ Setup

# unzip the contents of the downloaded archive to the JOSM Plugin directory
# unzip the contents of the downloaded archive to the JOSM Plugin directory
Linux Users put it to: .josm/plugins/ext_tools/scanaerial

# In JOSM press F12 and go to Ext_tools configuration
Expand All @@ -56,34 +56,34 @@
:B~ Configurationfile

{table~h 30; 70;}
key | function
fixedzoomlevel | use this zoomlevel, if Ext_tools did not tell via TZoom
wmsname | name of the WMS Source (only for the tag string)
wms_server_url | you may choose your favourite WMS server
projection | projection that is used on the WMS server
tile_sizex,-y | leave it to 256 unless you know what you do
douglas_peucker_epsilon | maximum roughness for smoothening the line
colour_str | colour sensitivity
maxfilter_setting | how many times should we apply the smoothening?
key | function
fixedzoomlevel | use this zoomlevel, if Ext_tools did not tell via TZoom
wmsname | name of the WMS Source (only for the tag string)
wms_server_url | you may choose your favourite WMS server
projection | projection that is used on the WMS server
tile_sizex,-y | leave it to 256 unless you know what you do
douglas_peucker_epsilon | maximum roughness for smoothening the line
colour_str | colour sensitivity
maxfilter_setting | how many times should we apply the smoothening?



:B~ Troubleshooting

_* if anything fails have a look at the error console.
_* if anything fails have a look at the error console.
Scanaerial is very verbous.

:B~ Found a bug?

_* https://github.com/jonasstein/scanaerial/issues

_* if you want to contribute, please
make a fork,
_* if you want to contribute, please
make a fork,
make your changes in the fork
do a pull request on this project site, or contact the author

:B~ Links
:B~ Links

_* OSM Wiki about scanaerial http://wiki.openstreetmap.org/wiki/Scanaerial

_* OSM Wiki about scanaerial http://wiki.openstreetmap.org/wiki/Scanaerial

:B~ Have fun!
3 changes: 2 additions & 1 deletion library_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""
Use this to detect missing libaries which are needed by scanaerial.
"""
from __future__ import print_function

import sys
from debug import debug
Expand All @@ -42,5 +43,5 @@

if check:
print("Everthing works fine, you may run scanaerial now.")

sleep(5)
3 changes: 2 additions & 1 deletion projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

from __future__ import division
if __name__ == "__main__":
exit(0)

Expand Down Expand Up @@ -63,7 +64,7 @@ def coords_by_tile(z, x, y, srs):
Converts (z,x,y) to coordinates of corner of srs-projected tile
"""
z -= 1
normalized_tile = (x / (2. ** z), 1. - (y / (2. ** z)))
normalized_tile = (x * 1.0 / (2. ** z), 1. - (y * 1.0 / (2. ** z)))
projected_bounds = from4326(projs[proj_alias.get(srs, srs)]["bounds"], srs)
maxp = [projected_bounds[2] - projected_bounds[0], projected_bounds[3] - projected_bounds[1]]
projected_coords = [(normalized_tile[0] * maxp[0]) + projected_bounds[0], (normalized_tile[1] * maxp[1]) + projected_bounds[1]]
Expand Down
Loading

0 comments on commit 72e8f61

Please sign in to comment.