Skip to content

Commit

Permalink
solves #179
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardoklinger committed Apr 14, 2015
1 parent 7a0dcaf commit f33b8a0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ You can choose between several basemap styles and define the initial extent of t

The popup for features is either a simple table with all your attributes or defined by the attribute 'html_exp' in your QGIS vector layer (check 'line_feature.shp' in the 'test_data' folder). If you want to use a defined symbol in your webmap add an attribute 'icon_exp' to your point shapefile and file it with a relative path on your PC or an HTML statement. You can define different icons for each feature. Please check index.html of the webmap to customize popup position regarding your chosen icon. You may find testdata in 'places_few_1_EPSG3857_categorized.shp' in the 'test_data' folder (Donkey designed by Gabriele Malaspina from the thenounproject.com).

If you want to export raster files keep in mind to save them as rendered images prior exporting (values must be integers in the range of 0 to 255).

You can also define a label in the webmap by adding the column 'label_exp' to your layer which will define the text to show in the label.

For single, categorized and graduated symbol point feature layers we are exporting radius (not for polygons), color and opacity. Unfortunately the export of forms and SVG is not embedded at the moment.

If you would like to create a legend you need to add the attributes 'legend_exp' (text to be shown) and 'legend_ico' (icon to be shown) to the desired layer and fill in the link to the icon and the text. Check the test files for details.
If you would like to create a legend you need to add the attributes 'legend_exp' (text to be shown) and 'legend_ico' (icon to be shown) to the desired layer and fill in the link to the icon and a text. Check the test files for details.

The 'locate' button will ask for access to geolocate the browser and will add a marker where the webmap user is found.

Expand All @@ -29,6 +31,8 @@ To define your own basemaps, you need to alter the file qgis2leaf_layerlist and
* Import the plugin using the normal "add plugin" method described [here](http://docs.qgis.org/2.2/en/docs/user_manual/plugins/plugins.html#managing-plugins 'qgis plugins').

## Version_changes
* 2015/04/14 v.1.5.2: solved raster export issues
* 2015/04/14 v.1.5.1: Added https://github.com/tomchadwin to authors
* 2015/03/26 v.1.5.0: Major code refactor; tidy output
* 2015/03/17 v.1.4.2: fixed hidden polygon layers; added pen styles
* 2014/12/11 v.1.4.1: bugs for labels fixes. style issue for labels solved
Expand Down Expand Up @@ -61,11 +65,11 @@ To define your own basemaps, you need to alter the file qgis2leaf_layerlist and
## Tests

You may find testdata in the "test_data" folder.
It was tested on Linux Mint/Ubuntu and Windows 7 with QGIS 2.6 and Python 2.7.5+
It was tested on Linux Mint/Ubuntu and Windows 7 with QGIS 2.8.1 and Python 2.7.5+

## Contributors

Currently we are working on this project as part of the blog [digital-geography.com](http://www.digital-geography.com 'digital-geography') and [geolicious.](http://www.geolicious.de 'geolicious')
Currently we are working on this project as part of the blog [digital-geography.com](http://www.digital-geography.com 'digital-geography'), [geolicious.](http://www.geolicious.de 'geolicious') and the [Northumberland National Park Authority](https://www.gov.uk/government/organisations/northumberland-national-park-authority 'NNPA.org.uk')
You find additional contributors in the changelog.

## License
Expand Down
5 changes: 3 additions & 2 deletions metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name=qgis2leaf
qgisMinimumVersion=2.0
description=Export your QGIS project to a leaflet based webmap.
about=QGIS2Leaf creates a webmap from your current QGIS vector features and rasters. Therefore it tries to copy the current styles to styles, leaflet will understand.
version=1.5.0
version=1.5.2
author=Riccardo Klinger, Geolicious; Tom Chadwin, Northumberland National Park Authority
[email protected]; [email protected]

Expand All @@ -22,7 +22,8 @@ [email protected]; [email protected]
# Optional items:

# Uncomment the following line and add your changelog entries:
changelog= 2015/04/14 v.1.5.1 Added https://github.com/tomchadwin to authors
changelog= 2015/04/14 v.1.5.2 solved raster export issues
2015/04/14 v.1.5.1 Added https://github.com/tomchadwin to authors
2015/03/26 v.1.5.0: Major code refactor; tidy output
2015/03/17 v.1.4.2: fixed hidden polygon layers; added pen styles
2014/12/11 v.1.4.1: bugs for labels fixes. style issue for labels solved
Expand Down
32 changes: 13 additions & 19 deletions qgis2leaf_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,17 @@ def qgis2leaf_exec(outputProjectFileName, basemapName, basemapMeta, basemapAddre
elif i.type() == 1:
if i.dataProvider().name() != "wms":
in_raster = str(i.dataProvider().dataSourceUri())
prov_raster = tempfile.gettempdir() + os.sep + 'exp_' + safeLayerName + 'prov.tif'
out_raster = dataStore + os.sep + 'exp_' + safeLayerName + '.jpg'

if str(i.dataProvider().metadata()[0:4]) == 'JPEG' and str(i.crs().authid()) == 'EPSG:4326':
shutil.copyfile(in_raster+".aux.xml", out_raster + ".aux.xml")
shutil.copyfile(in_raster, out_raster)
else:
processing.runalg("gdalogr:warpreproject",str(in_raster),str(i.crs().authid()),"EPSG:4326",0,1,"",prov_raster)
format = "jpeg"
driver = gdal.GetDriverByName( format )
src_ds = gdal.Open(prov_raster)
dst_ds = driver.CreateCopy( out_raster, src_ds, 0 )
dst_ds = None #free the dataset
src_ds = None #free the dataset
#ret = subprocess.check_call(['gdal_translate -of jpeg -outsize 100% 100% -a_srs EPSG:4326 ' + filename_raster + " " + out_raster_name], shell=True)
#ret2 = subprocess.check_call(['cp ' + filename_raster + ".aux.xml " + out_raster_name + ".aux.xml"], shell=True)

prov_raster = tempfile.gettempdir() + os.sep + 'exp_' + safeLayerName + '_prov.tif'
out_raster = dataStore + os.sep + 'exp_' + safeLayerName + '.png'
crsSrc = i.crs()
crsDest = QgsCoordinateReferenceSystem(4326)
xform = QgsCoordinateTransform(crsSrc, crsDest)
extentRep = xform.transform(i.extent())
extentRepNew = ','.join([str(extentRep.xMinimum()), str(extentRep.xMaximum()),str(extentRep.yMinimum()), str(extentRep.yMaximum())])
processing.runalg("gdalogr:warpreproject",in_raster,i.crs().authid(),"EPSG:4326","",0,1,0,-1,75,6,1,False,0,False,"",prov_raster)
print extentRepNew
processing.runalg("gdalogr:translate",prov_raster,100,True,"",0,"",extentRepNew,False,0,0,75,6,1,False,0,False,"",out_raster)

#now determine the canvas bounding box
#####now with viewcontrol
if extent == 'canvas extent':
Expand Down Expand Up @@ -307,7 +301,7 @@ def qgis2leaf_exec(outputProjectFileName, basemapName, basemapMeta, basemapAddre
middle = """
<script>
"""
print '>> ' + crsProj4
#print '>> ' + crsProj4
if matchCRS == True and crsAuthId != 'EPSG:4326':
print '>> ' + crsProj4
middle += """
Expand Down Expand Up @@ -832,7 +826,7 @@ def qgis2leaf_exec(outputProjectFileName, basemapName, basemapMeta, basemapAddre
print d
#print i.source()
else:
out_raster_name = 'data/' + 'exp_' + safeLayerName + '.jpg'
out_raster_name = 'data/' + 'exp_' + safeLayerName + '.png'
pt2 = i.extent()
crsSrc = i.crs() # WGS 84
crsDest = QgsCoordinateReferenceSystem(4326) # WGS 84 / UTM zone 33N
Expand Down
4 changes: 2 additions & 2 deletions ui_qgis2leaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui_qgis2leaf.ui'
#
# Created: Tue Dec 16 22:28:14 2014
# Created: Wed Apr 15 00:16:50 2015
# by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!
Expand Down Expand Up @@ -481,7 +481,7 @@ def retranslateUi(self, qgis2leaf):
"<p align=\"justify\" style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600; text-decoration: underline;\">General help:</span></p>\n"
"<p align=\"justify\" style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Sans\'; font-size:9pt;\">QGIS2leaf creates a webmap from your current QGIS vector features and rasters. Therefore it tries to copy the current vector styles to styles, leaflet will understand. If your data has an attribute called </span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600; font-style:italic;\">html_exp</span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600;\"> </span><span style=\" font-family:\'Sans\'; font-size:9pt;\">it will use this for the</span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600;\"> popup content. </span><span style=\" font-family:\'Sans\'; font-size:9pt;\">Otherwise it will create a </span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600;\">simple table</span><span style=\" font-family:\'Sans\'; font-size:9pt;\"> from all of your attributes and values. </span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600;\"> </span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600; font-style:italic;\">label_exp </span><span style=\" font-family:\'Sans\'; font-size:9pt;\">will be used to fill labels if not defined by the label section itself. Furthermore you can define an </span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600;\">icon for your point</span><span style=\" font-family:\'Sans\'; font-size:9pt;\"> layers using an attribute called </span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600; font-style:italic;\">icon_exp</span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600;\">.</span><span style=\" font-family:\'Sans\'; font-size:9pt;\"> Each feature should have an </span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600;\">absolute path</span><span style=\" font-family:\'Sans\'; font-size:9pt;\"> on your current system or provide a </span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600;\">link to the image</span><span style=\" font-family:\'Sans\'; font-size:9pt;\"> (preferable *.svg or *.png). You may find suitable examples in the test_data folder.</span></p>\n"
"<p align=\"justify\" style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Sans\'; font-size:9pt;\">When you\'re interested in building a legend as well, you need to fill the column </span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600; font-style:italic;\">legend_exp</span><span style=\" font-family:\'Sans\'; font-size:9pt;\"> with a text and </span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600; font-style:italic;\">legend_ico</span><span style=\" font-family:\'Sans\'; font-size:9pt;\"> with the path to an icon which should be shown in the legend for the particular layer. This works only for local layers and non-raster layers. See the example files for details.</span></p>\n"
"<p align=\"justify\" style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Sans\'; font-size:9pt;\">Raster images will be translated to EPSG:4326/jpg using GDAL python bindings.</span></p>\n"
"<p align=\"justify\" style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Sans\'; font-size:9pt;\">Raster images will be translated to EPSG:4326/jpg using GDAL python bindings.</span><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600;\"> Attention: </span><span style=\" font-family:\'Sans\'; font-size:9pt;\">Make sure to store the raster as rendered image prior exporting it with qgis2leaf!</span></p>\n"
"<p align=\"justify\" style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Sans\'; font-size:9pt;\">* The export with leaflet matching the project CRS is beta!!!</span></p>\n"
"<p align=\"justify\" style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'Sans\'; font-size:9pt; font-weight:600; text-decoration: underline;\">GUI help:</span></p>\n"
"<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li style=\" font-family:\'Sans\'; font-size:9pt;\" align=\"justify\" style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Press &quot;<span style=\" font-weight:600;\">get layers</span>&quot; to add/reload your vector layers to the plugin. You can select the layers to export.</li>\n"
Expand Down
2 changes: 1 addition & 1 deletion ui_qgis2leaf.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ p, li { white-space: pre-wrap; }
&lt;p align=&quot;justify&quot; style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600; text-decoration: underline;&quot;&gt;General help:&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt;QGIS2leaf creates a webmap from your current QGIS vector features and rasters. Therefore it tries to copy the current vector styles to styles, leaflet will understand. If your data has an attribute called &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600; font-style:italic;&quot;&gt;html_exp&lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600;&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt;it will use this for the&lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600;&quot;&gt; popup content. &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt;Otherwise it will create a &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600;&quot;&gt;simple table&lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt; from all of your attributes and values. &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600;&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600; font-style:italic;&quot;&gt;label_exp &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt;will be used to fill labels if not defined by the label section itself. Furthermore you can define an &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600;&quot;&gt;icon for your point&lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt; layers using an attribute called &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600; font-style:italic;&quot;&gt;icon_exp&lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt; Each feature should have an &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600;&quot;&gt;absolute path&lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt; on your current system or provide a &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600;&quot;&gt;link to the image&lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt; (preferable *.svg or *.png). You may find suitable examples in the test_data folder.&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt;When you're interested in building a legend as well, you need to fill the column &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600; font-style:italic;&quot;&gt;legend_exp&lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt; with a text and &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600; font-style:italic;&quot;&gt;legend_ico&lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt; with the path to an icon which should be shown in the legend for the particular layer. This works only for local layers and non-raster layers. See the example files for details.&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt;Raster images will be translated to EPSG:4326/jpg using GDAL python bindings.&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt;Raster images will be translated to EPSG:4326/jpg using GDAL python bindings.&lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600;&quot;&gt; Attention: &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt;Make sure to store the raster as rendered image prior exporting it with qgis2leaf!&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt;&quot;&gt;* The export with leaflet matching the project CRS is beta!!!&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans'; font-size:9pt; font-weight:600; text-decoration: underline;&quot;&gt;GUI help:&lt;/span&gt;&lt;/p&gt;
&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; font-family:'Sans'; font-size:9pt;&quot; align=&quot;justify&quot; style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Press &amp;quot;&lt;span style=&quot; font-weight:600;&quot;&gt;get layers&lt;/span&gt;&amp;quot; to add/reload your vector layers to the plugin. You can select the layers to export.&lt;/li&gt;
Expand Down

0 comments on commit f33b8a0

Please sign in to comment.