Code Monkey home page Code Monkey logo

map-stylizer's Introduction

map-stylizer

GUI written in Python to parse OSM (OpenStreetMap) files and render them onscreen. Layers may be toggled on/off and drawing may be customized.


This program allows a user to render OSM files within the GUI. The GUI enables the user to easily modify which layers are visible and the style of these layers.

Basic Demo Video

Steps

  1. Download the source code open the program by typing python main.py in the command line.
  2. Open your browser of choice to OpenStreetMap.
  3. Click the "Export" tab and select the "Manually select a different area" link. Shape and place the box over the region from which you want map data. Click "Export" to download the OSM file for the box you've drawn. If you get an error that you've selected too many nodes, you may alternatively click "Overpass API."
    Note: Ensure your downloaded OSM file is around 30MB. Larger files will noticeably slow the program.
  4. Open your OSM file using the GUI.
  5. Edit away!

Editing

  • Choose which layers you want visible
    Note: Layers are grouped by OSM keys (i.e., "highway," "waterway," etc.)
  • Change the style of line or fill layers
    • Line layers are QPen objects, so you can specify the line's width, color, style, cap style, and join style
    • Fill layers are QColor objects, so you can only specify their color
  • When you save an image, the resulting configuration is saved into the "configs" folder so you can reimport these settings for another project
  • You can also automate the creation of configurations via your own script, where you use the Configuration class to set colors of layers en masse

Adding Additional Layers

When you import an OSM file and begin manipulating it, you will likely notice warnings on your command prompt indicating there are additional layers not rendering because they need to be added. This is okay, as I've added the majority of layers you would be interested in; however, if you would like to add the layers mentioned, follow the below steps:

  1. In the constants.py file:
    1. Create a unique (both variable name and variable value) VAL variable under the appropriate KEY group
    2. Create a unique (both variable name and variable value) CONFIG_STYLE variable under the appropriate KEY group
    3. Connect the new VAL and new CONFIG_STYLE in the DATA_GROUPS dictionary
  2. Finally, in the configuration.py file, connect the CONFIG_STYLE to a QPen (for a layer to be rendered as a line) or QColor (for a layer to be rendered as a fill)

map-stylizer's People

Contributors

absolute-tinkerer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

map-stylizer's Issues

Error importing MainWindowHandlers

I could install using pip every other package exept for this one. Pylance could not resolve the package. Just saying, I am probably not going to check this out ever again. Its 1 am and im bored.

TypeError: drawText argument 1 has unexpected type 'float'

After cloning the repo and attempting to start the program, I received this error message:

(venv) me@M1-MacBook-Air map-stylizer % python3.10 main.py                                               
Traceback (most recent call last):
  File ".../map-stylizer/src/gui/Widgets/mapwidget.py", line 46, in paintEvent
    self._drawPreloadScreen(p)
  File ".../map-stylizer/src/gui/Widgets/mapwidget.py", line 139, in _drawPreloadScreen
    p.drawText(self.width()/2-w/2, self.height()/2+h/2, text)
TypeError: arguments did not match any overloaded call:
  drawText(self, p: Union[QPointF, QPoint], s: str): argument 1 has unexpected type 'float'
  drawText(self, rectangle: QRectF, flags: int, text: str): argument 1 has unexpected type 'float'
  drawText(self, rectangle: QRect, flags: int, text: str): argument 1 has unexpected type 'float'
  drawText(self, rectangle: QRectF, text: str, option: QTextOption = QTextOption()): argument 1 has unexpected type 'float'
  drawText(self, p: QPoint, s: str): argument 1 has unexpected type 'float'
  drawText(self, x: int, y: int, width: int, height: int, flags: int, text: str): argument 1 has unexpected type 'float'
  drawText(self, x: int, y: int, s: str): argument 1 has unexpected type 'float'
zsh: abort      python3.10 main.py

This type error is easily fixed by following the stack trace to mapwidget:139 and casting both numeral arguments of the p.drawText() invocation with a simple int().

Will create a pull request in case this solution is deemed acceptable.

Crash on converted files

Hello,
I am using France osm.pbf I got from geofabric and converted it into a .osm with osmconvert (The file size is surprisingly only around 200Mo).
When loading the file inside the program, it crash and display this message :

Traceback (most recent call last):
  File "C:\Users\Utilisateur\Documents\code\python-style-map\src\gui\MainWindow\MainWindowHandlers.py", line 203, in loadOSMFile
    self._map.setOSMFile(fileName)
  File "C:\Users\Utilisateur\Documents\code\python-style-map\src\gui\Widgets\mapwidget.py", line 80, in setOSMFile
    self._map = Map(self.width(), self.height(), fname, self._config)
  File "C:\Users\Utilisateur\Documents\code\python-style-map\src\core\Map.py", line 139, in __init__
    root = ET.parse(fname).getroot()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\xml\etree\ElementTree.py", line 1202, in parse
    tree.parse(source, parser)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\xml\etree\ElementTree.py", line 595, in parse
    self._root = parser._parse_whole(source)
xml.etree.ElementTree.ParseError: encoding specified in XML declaration is incorrect: line 1, column 31

jpeg file is not generated

Hello,

On Ubuntu 18, everything works fine until clicking on "Save image". After choosing a name, the final is not generated but the configs are saved.

The only log I have in the terminal is :

  • WARNING: tag="landuse"; key="school" will not render unless manually added!

Any ideas ? Am I missing any libraries ?

Thanks !

Wrong multipolygons rendering

Actual behaviour

test_1.osm

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6">
 <bounds minlat="60.09" minlon="29.66" maxlat="60.16" maxlon="29.75"/>
 <node id="1" version="1" lat="60.141334" lon="29.743080"/>
 <node id="2" version="1" lat="60.155005" lon="29.704971"/>
 <node id="3" version="1" lat="60.142188" lon="29.667892"/>
 <node id="4" version="1" lat="60.107644" lon="29.666519"/>
 <node id="5" version="1" lat="60.098232" lon="29.707718"/>
 <node id="6" version="1" lat="60.111579" lon="29.745483"/>
 <node id="7" version="1" lat="60.111579" lon="29.694328"/>
 <node id="8" version="1" lat="60.125263" lon="29.694328"/>
 <node id="9" version="1" lat="60.133812" lon="29.744453"/>
 <way id="10" version="1">
  <nd ref="1"/>
  <nd ref="2"/>
  <nd ref="3"/>
  <nd ref="4"/>
  <nd ref="5"/>
  <nd ref="6"/>
 </way>
 <way id="11" version="1">
  <nd ref="6"/>
  <nd ref="7"/>
 </way>
 <way id="12" version="1">
  <nd ref="7"/>
  <nd ref="8"/>
 </way>
 <way id="13" version="1">
  <nd ref="8"/>
  <nd ref="9"/>
 </way>
 <way id="14" version="1">
  <nd ref="9"/>
  <nd ref="1"/>
 </way>
 <relation id="9" version="1">
  <member type="way" ref="10" role="outer"/>
  <member type="way" ref="11" role="outer"/>
  <member type="way" ref="12" role="outer"/>
  <member type="way" ref="13" role="outer"/>
  <member type="way" ref="14" role="outer"/>
  <tag k="type" v="multipolygon"/>
  <tag k="natural" v="water"/>
 </relation>
</osm>

Result (wrong):
scr1

test_2.osm

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6">
 <bounds minlat="60.09" minlon="29.66" maxlat="60.16" maxlon="29.75"/>
 <node id="1" version="1" lat="60.141334" lon="29.743080"/>
 <node id="2" version="1" lat="60.155005" lon="29.704971"/>
 <node id="3" version="1" lat="60.142188" lon="29.667892"/>
 <node id="4" version="1" lat="60.107644" lon="29.666519"/>
 <node id="5" version="1" lat="60.098232" lon="29.707718"/>
 <node id="6" version="1" lat="60.111579" lon="29.745483"/>
 <node id="7" version="1" lat="60.111579" lon="29.694328"/>
 <node id="8" version="1" lat="60.125263" lon="29.694328"/>
 <node id="9" version="1" lat="60.133812" lon="29.744453"/>
 <way id="10" version="1">
  <nd ref="1"/>
  <nd ref="2"/>
  <nd ref="3"/>
  <nd ref="4"/>
  <nd ref="5"/>
  <nd ref="6"/>
 </way>
 <way id="11" version="1">
  <nd ref="6"/>
  <nd ref="7"/>
  <nd ref="8"/>
 </way>
 <way id="12" version="1">
  <nd ref="8"/>
  <nd ref="9"/>
 </way>
 <way id="13" version="1">
  <nd ref="9"/>
  <nd ref="1"/>
 </way>
 <relation id="9" version="1">
  <member type="way" ref="10" role="outer"/>
  <member type="way" ref="11" role="outer"/>
  <member type="way" ref="12" role="outer"/>
  <member type="way" ref="13" role="outer"/>
  <tag k="type" v="multipolygon"/>
  <tag k="natural" v="water"/>
 </relation>
</osm>

Result (wrong):
scr2

test_3.osm

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6">
 <bounds minlat="60.09" minlon="29.66" maxlat="60.16" maxlon="29.75"/>
 <node id="1" version="1" lat="60.141334" lon="29.743080"/>
 <node id="2" version="1" lat="60.155005" lon="29.704971"/>
 <node id="3" version="1" lat="60.142188" lon="29.667892"/>
 <node id="4" version="1" lat="60.107644" lon="29.666519"/>
 <node id="5" version="1" lat="60.098232" lon="29.707718"/>
 <node id="6" version="1" lat="60.111579" lon="29.745483"/>
 <node id="7" version="1" lat="60.111579" lon="29.694328"/>
 <node id="8" version="1" lat="60.125263" lon="29.694328"/>
 <node id="9" version="1" lat="60.133812" lon="29.744453"/>
 <way id="10" version="1">
  <nd ref="1"/>
  <nd ref="2"/>
  <nd ref="3"/>
  <nd ref="4"/>
  <nd ref="5"/>
  <nd ref="6"/>
 </way>
 <way id="11" version="1">
  <nd ref="6"/>
  <nd ref="7"/>
  <nd ref="8"/>
 </way>
 <way id="12" version="1">
  <nd ref="8"/>
  <nd ref="9"/>
  <nd ref="1"/>
 </way>
 <relation id="9" version="1">
  <member type="way" ref="10" role="outer"/>
  <member type="way" ref="11" role="outer"/>
  <member type="way" ref="12" role="outer"/>
  <tag k="type" v="multipolygon"/>
  <tag k="natural" v="water"/>
 </relation>
</osm>

Result (wrong):
scr3

test_4.osm

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6">
 <bounds minlat="60.09" minlon="29.66" maxlat="60.16" maxlon="29.75"/>
 <node id="1" version="1" lat="60.141334" lon="29.743080"/>
 <node id="2" version="1" lat="60.155005" lon="29.704971"/>
 <node id="3" version="1" lat="60.142188" lon="29.667892"/>
 <node id="4" version="1" lat="60.107644" lon="29.666519"/>
 <node id="5" version="1" lat="60.098232" lon="29.707718"/>
 <node id="6" version="1" lat="60.111579" lon="29.745483"/>
 <node id="7" version="1" lat="60.111579" lon="29.694328"/>
 <node id="8" version="1" lat="60.125263" lon="29.694328"/>
 <node id="9" version="1" lat="60.133812" lon="29.744453"/>
 <way id="10" version="1">
  <nd ref="1"/>
  <nd ref="2"/>
  <nd ref="3"/>
  <nd ref="4"/>
  <nd ref="5"/>
  <nd ref="6"/>
 </way>
 <way id="11" version="1">
  <nd ref="6"/>
  <nd ref="7"/>
  <nd ref="8"/>
  <nd ref="9"/>
  <nd ref="1"/>
 </way>
 <relation id="9" version="1">
  <member type="way" ref="10" role="outer"/>
  <member type="way" ref="11" role="outer"/>
  <tag k="type" v="multipolygon"/>
  <tag k="natural" v="water"/>
 </relation>
</osm>

Result (OK):
scr4

Expected behaviour

All test_{1,2,3,4}.osm should be rendered the same way.
Just for reference, JOSM rendering:
scr0

Test files

test_osm.tar.gz

Crash with AttributeError: 'NoneType' object has no attribute 'convertLong'

Gentoo with python 3.7

$ python3.7 ./main.py 
Traceback (most recent call last):
  File "/mnt/notes.data/OSM/map-stylizer/src/gui/MainWindow/MainWindowHandlers.py", line 203, in loadOSMFile
    self._map.setOSMFile(fileName)
  File "/mnt/notes.data/OSM/map-stylizer/src/gui/Widgets/mapwidget.py", line 80, in setOSMFile
    self._map = Map(self.width(), self.height(), fname, self._config)
  File "/mnt/notes.data/OSM/map-stylizer/src/core/Map.py", line 147, in __init__
    node = Node(child.attrib, transform)
  File "/mnt/notes.data/OSM/map-stylizer/src/core/Map.py", line 28, in __init__
    self._x = transform.convertLong(float(attrib['lon']))
AttributeError: 'NoneType' object has no attribute 'convertLong'
Aborted

when opening attached file

zdanice_2020_cesty.zip

file works fine with JOSM/Maperitive.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.