Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding "name" as a class field makes the script fail #18

Open
stevevance opened this issue Feb 13, 2017 · 6 comments
Open

Adding "name" as a class field makes the script fail #18

stevevance opened this issue Feb 13, 2017 · 6 comments

Comments

@stevevance
Copy link
Member

stevevance commented Feb 13, 2017

Hey @fitnr, I want to style buildings with names differently than those without names, but when I include "name" as a class field, the script fails.

My workaround in the meantime is to only query Overpass for buildings with names, but I want buildings with and without names so that I can style them differently.

Sidenote: Is there a way to create a CSS class that fits any non-blank value, or negative value, like I want "building!=yes", to excluded non-categorized buildings.

Error when using "name" as a class field

make CLASSFIELDS=name png/b_wards_2015/ward-33.png --what-if=osm/buildings.osm
ogr2ogr bg/multipolygons/buildings.shp osm/buildings.osm multipolygons -f 'ESRI Shapefile' -lco ENCODING=UTF-8 -overwrite -skipfailures -t_srs EPSG:3435
Warning 1: Value '"contact:fax"=>"+1 262 857 3383","contact:phone"=>"+1 262 857 3377","contact:phone_reservations"=>"+1 800 333 3333","contact:website"=>"https://www.radisson.com/pleasant-prairie-hotel-wi-53158/wikenosh","operator"=>"Carlson Rezidor Hotel Group","rooms"=>"120","start_date"=>"1999"' of field other_tags has been truncated to 254 characters.
This warning will not be emitted any more for that layer.
svgis draw -o svg/b_wards_2015/ward-33.svg bg/multipolygons/parks.shp bg/multipolygons/water.shp bg/multipolygons/buildings.shp bg/lines/roads.shp bg/lines/transit.shp bg/points/stops.shp shp/b_wards_2015/ward-33.shp --no-viewbox --inline --clip --crs file --scale 10 --padding 1200 --precision 0 --simplify 90 --class-fields name --style style.css --bounds $(svgis bounds shp/b_wards_2015/ward-33.shp)
Traceback (most recent call last):
  File "/usr/local/bin/svgis", line 11, in <module>
    sys.exit(main())
  File "/Library/Python/2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Library/Python/2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Python/2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Python/2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/svgis/cli.py", line 175, in draw
    click.echo(svgis.map(layer, **kwargs).encode('utf-8'), file=output)
  File "/Library/Python/2.7/site-packages/svgis/svgis.py", line 79, in map
    ).compose(**kwargs)
  File "/Library/Python/2.7/site-packages/svgis/svgis.py", line 447, in compose
    drawing = self._draw(members, scalar, **drgs)
  File "/Library/Python/2.7/site-packages/svgis/svgis.py", line 497, in _draw
    drawing = _style.inline(drawing, svgargs['style'])
  File "/Library/Python/2.7/site-packages/svgis/style.py", line 173, in inline
    doc = ElementTree.fromstring(svg.encode('utf-8'))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1300, in XML
    parser.feed(text)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1642, in feed
    self._raiseerror(v)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 95, column 49618
make: *** [svg/b_wards_2015/ward-33.svg] Error 1

It doesn't happen for any other field name that I've tried, like "cycleway".

I see in the svgis README example that it's supposed to work fine with "name" as a field.

@fitnr
Copy link
Collaborator

fitnr commented Feb 17, 2017

My guess is that this is related to the fact that "name" is an existing SVG attribute. However, it might be the something else in the OSM. Can you send me the osm file and I'll try messing with it?

@stevevance
Copy link
Member Author

stevevance commented Feb 18, 2017

Here's the OSM file I'm using.
buildings.osm.zip

Take note that I've also changed the buildings query, to only grab buildings that have a name, are a train station, or are a school.

I did this for practical and aesthetic reasons: Too many buildings in the bounding box causes Overpass to run out of memory immediately and quit. I like the outcome that shows only "significant" buildings.

Here's the current buildings query:

[out:xml][timeout:600][bbox:{{bbox}}];
(
    way["name"]["building"]({{bbox}});
	relation["name"]["building"]({{bbox}});
	
	way["building"="school"]({{bbox}});
	relation["building"="school"]({{bbox}});
	
	way["amenity"="school"]({{bbox}});
	relation["amenity"="school"]({{bbox}});
	
	way["public_transport"="station"]({{bbox}});
);
(
    ._;
    >;
);
out body qt;

I don't have my CSS anymore, but I think it was:

.name {
    stroke: none;
    fill: #ff3388 /* random color */
}

Which, now that I look at it, seems wrong. Maybe the selector was #buildings .name. How the styling works with #ids and .classes confuses me!

@fitnr
Copy link
Collaborator

fitnr commented Feb 23, 2017

I can't reproduce the error. Can I suggest trying it (a) with no css, (b) without the other_tags field (delete it in QGIS).

For the CSS, here what the SVG file looks like for a file named foobar.shp with columns alpha and beta, where SVGIS is run with --class-fields alpha:

<g class="alpha beta" id="foobar">
    <path class="polygon foobar alpha_value1">
    <polygon class="polygon foobar alpha_value2">
</g>

This works just like CSS on the web with div and p tags. To address all of the shapes in foobar with CSS, use a selector like this:

#foobar .polygon { fill: green }

@stevevance
Copy link
Member Author

stevevance commented Feb 23, 2017

Test A.1:

# SVGIS flags and settings
# snipped
CLASSFIELDS ?= highway,railway,amenity,landuse,cycleway,bicycle,tunnel,building

Result: Succeeds in creating the image.

Test A.2:

# SVGIS flags and settings
# snipped
CLASSFIELDS ?= highway,railway,amenity,landuse,cycleway,bicycle,tunnel,building,name
# the difference is that "name" is added to the CLASSFIELDS list

Result: Fails to create the image, with this error:

Traceback (most recent call last):
  File "/usr/local/bin/svgis", line 11, in <module>
    sys.exit(main())
  File "/Library/Python/2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Library/Python/2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Python/2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Python/2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/svgis/cli.py", line 175, in draw
    click.echo(svgis.map(layer, **kwargs).encode('utf-8'), file=output)
  File "/Library/Python/2.7/site-packages/svgis/svgis.py", line 79, in map
    ).compose(**kwargs)
  File "/Library/Python/2.7/site-packages/svgis/svgis.py", line 447, in compose
    drawing = self._draw(members, scalar, **drgs)
  File "/Library/Python/2.7/site-packages/svgis/svgis.py", line 497, in _draw
    drawing = _style.inline(drawing, svgargs['style'])
  File "/Library/Python/2.7/site-packages/svgis/style.py", line 173, in inline
    doc = ElementTree.fromstring(svg.encode('utf-8'))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1300, in XML
    parser.feed(text)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1642, in feed
    self._raiseerror(v)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 110, column 88749
make: *** [svg/communityarea/communityarea-albany-park.svg] Error 1
rm shp/communityarea/communityarea-albany-park.shp

Test B:

# SVGIS flags and settings
# snipped
CLASSFIELDS ?= highway,railway,amenity,landuse,cycleway,bicycle,tunnel,building,name
# the difference is that "name" is added to the CLASSFIELDS list

Result: Fails, with this error message:

Traceback (most recent call last):
  File "/usr/local/bin/svgis", line 11, in <module>
    sys.exit(main())
  File "/Library/Python/2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Library/Python/2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Python/2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Python/2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/svgis/cli.py", line 175, in draw
    click.echo(svgis.map(layer, **kwargs).encode('utf-8'), file=output)
  File "/Library/Python/2.7/site-packages/svgis/svgis.py", line 79, in map
    ).compose(**kwargs)
  File "/Library/Python/2.7/site-packages/svgis/svgis.py", line 447, in compose
    drawing = self._draw(members, scalar, **drgs)
  File "/Library/Python/2.7/site-packages/svgis/svgis.py", line 497, in _draw
    drawing = _style.inline(drawing, svgargs['style'])
  File "/Library/Python/2.7/site-packages/svgis/style.py", line 173, in inline
    doc = ElementTree.fromstring(svg.encode('utf-8'))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1300, in XML
    parser.feed(text)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1642, in feed
    self._raiseerror(v)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 110, column 88738
make: *** [svg/communityarea/communityarea-albany-park.svg] Error 1
rm shp/communityarea/communityarea-albany-park.shp
# Note that the line number is the same as Test A.2, but the column number is different. 

Test C:
I renamed the name field to names.

Result: Fails, with the following error:

# same as above
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 110, column 87442

@fitnr
Copy link
Collaborator

fitnr commented Feb 24, 2017

OK, then there's a bug in how svgis is escaping the CSS. What version are you using? I'm on svgis 0.4.4.

Can you add your CSS file to the issue I just opened in the svgis repo?

@stevevance
Copy link
Member Author

@fitnr I added my CSS to that issue.

I'm using svgis 0.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants