QGIS: Difference between revisions
Brian Wilson (talk | contribs) mNo edit summary |
Brian Wilson (talk | contribs) |
||
Line 149: | Line 149: | ||
I disabled /usr/lib/libgdal by renaming it just to be on the safe side. | I disabled /usr/lib/libgdal by renaming it just to be on the safe side. | ||
== Python problems == | |||
I was getting a failure on startup on one Mac but not the other. Hmm. I try to keep them pretty much the same. | |||
It would not load a plugin resulting in having no "Processing" option. | |||
Stack trace: | |||
<pre> | |||
Couldn't load plugin processing due to an error when calling its classFactory() method | |||
AttributeError: dlsym(0x7fc4babeda20, GEOSGeom_createEmptyCollection): symbol not found | |||
Traceback (most recent call last): | |||
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 333, in startPlugin | |||
plugins[packageName] = package.classFactory(iface) | |||
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/__init__.py", line 38, in classFactory | |||
return ProcessingPlugin(iface) | |||
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/ProcessingPlugin.py", line 58, in __init__ | |||
Processing.initialize() | |||
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/core/Processing.py", line 148, in initialize | |||
Processing.addProvider(c()) | |||
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py", line 225, in __init__ | |||
from .Polygonize import Polygonize | |||
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import | |||
mod = _builtin_import(name, globals, locals, fromlist, level) | |||
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/algs/qgis/Polygonize.py", line 28, in | |||
from shapely.ops import polygonize | |||
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import | |||
mod = _builtin_import(name, globals, locals, fromlist, level) | |||
File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/ops.py", line 13, in | |||
from shapely.geos import lgeos | |||
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import | |||
mod = _builtin_import(name, globals, locals, fromlist, level) | |||
File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/geos.py", line 161, in | |||
prototype(_lgeos, geos_version) | |||
File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/ctypes_declarations.py", line 162, in prototype | |||
lgeos.GEOSGeom_createEmptyCollection.restype = c_void_p | |||
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__ | |||
func = self.__getitem__(name) | |||
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__ | |||
func = self._FuncPtr((name_or_ordinal, self)) | |||
AttributeError: dlsym(0x7fc4babeda20, GEOSGeom_createEmptyCollection): symbol not found | |||
Python version: 2.7.10 (default, Oct 23 2015, 19:19:21) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] | |||
QGIS version: 2.18.2 Las Palmas, exported | |||
Python Path: | |||
/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing | |||
/Applications/QGIS.app/Contents/MacOS/../Resources/python | |||
/Users/bwilson/.qgis2/python | |||
/Users/bwilson/.qgis2/python/plugins | |||
/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins | |||
/Library/Frameworks/SQLite3.framework/Versions/C/Python/2.7 | |||
/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages | |||
/Library/Python/2.7/site-packages/scipy-override | |||
/Library/Python/2.7/site-packages/numpy-override | |||
/Library/Python/2.7/site-packages/matplotlib-override | |||
/Library/Frameworks/GDAL.framework/Versions/2.1/Python/2.7/site-packages | |||
/Library/Python/2.7/site-packages/PySAL-1.12.0-py2.7.egg | |||
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip | |||
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 | |||
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin | |||
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac | |||
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages | |||
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python | |||
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk | |||
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old | |||
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload | |||
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC | |||
/Library/Python/2.7/site-packages | |||
/Library/Python/2.7/site-packages/PIL | |||
/Users/bwilson/.qgis2//python | |||
</pre> | |||
What is different? | |||
PATH is the same. I might want to change it on both machines to prefer /usr/local/bin/python but that is not the problem. | |||
== Building QGIS from source == | == Building QGIS from source == |
Revision as of 01:43, 15 January 2017
I looked for a spatial data browser and found GeoApt Spatial Data Browser. I got interested in adding to it, so I started looking at its internals. I became more curious about QGIS.
Working with OpenStreetMap
Brian H wants to display a shapefile, and clip part of it out to use in JOSM for uploading to OpenStreetMap.
I think there is an OSM plugin for QGIS but the workflow we came up with is to extract the data you want to add in QGIS, save it in a shapefile, and then start up JOSM and load the shapefile there for upload to OpenStreetMap.
Displaying OSM as a tiled layer in QGIS
I'd like to be able to see what data is already in OpenStreetMap while running QGIS. Both for day to day usage in mapping and for OpenStreetMap projects.
(Thanks Nick)
Save this text into a file with the .xml extension. Variations on this will work for ANY tiled map service, not just OSM. In QGIS, use "Add Raster Layer" and navigate to the file you saved. Voila! A base map.
<GDAL_WMS> <Service name="TMS"> <ServerUrl>http://tile.openstreetmap.org/${z}/${x}/${y}.png</ServerUrl> </Service> <DataWindow> <UpperLeftX>-20037508.34</UpperLeftX> <UpperLeftY>20037508.34</UpperLeftY> <LowerRightX>20037508.34</LowerRightX> <LowerRightY>-20037508.34</LowerRightY> <TileLevel>18</TileLevel> <TileCountX>1</TileCountX> <TileCountY>1</TileCountY> <YOrigin>top</YOrigin> </DataWindow> <Projection>EPSG:900913</Projection> <BlockSizeX>256</BlockSizeX> <BlockSizeY>256</BlockSizeY> <BandsCount>3</BandsCount> <Cache /> </GDAL_WMS>
I leave the map in Web Mercator but you can do reprojection on the fly if you want.
Screenshot of Finley NWR area.
Log messages
I did actually find the button for this (see above screenshot) and now I can't find it again. Please tell me what I did. :-) The user manual I found is wrong. :-( Nick mentioned how great it would be to see error messages when trying to load a WMS layer.
Reprojection on the fly
or WHERE'S MY DATA??? I can't see it!
By default, QGIS has reprojection turned off. So if you bring in a layer in web mercator and then bring in a shapefile that is in a different projection, the layers will not line up.
- File->Project Properties (or control-shift-P)
- Coordinate Reference System (CRS) tab
- Check the box "Enable 'on the fly' CRS transformation"
The map should now render all the layers in the right places. QGIS 1.9 is a little buggy, so you might have to do this before adding layers. Not sure. It usually works for me but I sat here working with Nick and it was troublesome.
Adding a shapefile with hydro data
Download the shapefile, for example, for Benton county. http://gis.co.benton.or.us/GISDataDownload/Natural_Features/water.zip Unzip it someplace convenient.
- In QGIS, click on "Add Vector Layer" (icon: a green map with a +)
- Click Browse and find the water.shp file.
- Click Open. If you can't see the layer then try right-clicking the layer in the table of contents and select Zoom To Layer Extent.
- Set the CRS. Properties (double click on the layer name) "General" Click "Specify CRS" and set it to EPSG:2913 NAR83(HARN_ / Oregon North (ft)
- For this particular line layer you might want to use the Properties (double click on the layer name) "Style" tab to make the color blue and make the line a little wider (.36 works for me).
Zoomed into Finley NWR my map looks like this now. I used purple for the water shapefile so it's easier to see.
Extracting data from a layer
Create a shapefile to define region of interest
- Create a new shapefile to define a region of interest. To do so click "New Shapefile Layer" (green map with yellow star)
The new layer will be added to your table of contents.
- As above, set its CRS to EPSG:2913. The CRS settings HAVE TO BE THE SAME for the clip operation to work.
- Select that layer in the table of contents by clicking on it.
- Click on "Toggle editing" (a blue pen) -- the button should stay "depressed".
- Click on "Create new feature" (A polygon with red vertices)
Now you can create a polygon around your area of interest on the map. Left click = add vertex Right click = done. Enter an ID value (I used "1") and then stop editing and save your changes. (Click "Toggle editing" again.)
Region of interest shows up in blue on my map.
Clip water features using region of interest
In the "Vector" menu (in the menu toolbar at the top) use Geoprocessing Tools->Clip and select the layers you want to use.
In this example,
- The "Input vector layer" is "water"
- The "Clip layer" is "finley_roi"
- Set the "Output shapefile" as you desire, and
- click ok.
Here I have dragged the water_in_finley to the top of the table of contents, changed it to green, and unchecked OSM layer to make it visible.
Reproject and export
I know you can use a shapefile in JOSM but you can export to many other formats (KML, for example). I need to export to WGS84 (EPSG:4326) too
To export the data (and reproject it),
- Right click on the layer in the table of contents and select "Save As..."
- Set the Format (I choose KML, Brian H leaves it at Shapefile)
- Set the name
- Select the correct CRS (WGS 84)
- Click okay.
and we're done.
Working with the QGIS package
07-18-13 Still working on this.... ignore the rest of this page!
Okay, my problem is that I want to use a custom built GDAL because I need to be able to read ESRI file geodatabases but don't want to take on building QGIS right now.
I am getting the version of QGIS from "http://qgis.org/debian-nightly quantal main", but this packaged QGIS depends on a pre-built GDAL package. This means I have to bypass the pre-built GDAL libraries after they have been installed.
sudo apt-get install qgis Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: gdal-bin grass-core libarmadillo3 libavdevice53 libcoin60 libdap11 libdapclient3 libepsilon0 libgdal1 libgraphicsmagick3 libhdf4-0-alt libhdf5-7 libnetcdfc7 libopenscenegraph80 libopenthreads14 libosgearth1 libqgis1.9.0 libqscintilla2-8 libqwt6 libxerces-c28 libxine1 libxine1-bin libxine1-ffmpeg libxine1-misc-plugins libxine1-plugins libzip2 python-egenix-mxdatetime python-egenix-mxtools python-gdal python-psycopg2 python-pyspatialite python-qgis python-qgis-common python-qscintilla2 qgis-common qgis-plugin-globe qgis-plugin-globe-common qgis-plugin-grass qgis-plugin-grass-common qgis-providers qgis-providers-common
After installing I can see that it's not using the generic libgdal, good. See ldd /usr/bin/qgis.bin output.
I disabled /usr/lib/libgdal by renaming it just to be on the safe side.
Python problems
I was getting a failure on startup on one Mac but not the other. Hmm. I try to keep them pretty much the same. It would not load a plugin resulting in having no "Processing" option.
Stack trace:
Couldn't load plugin processing due to an error when calling its classFactory() method AttributeError: dlsym(0x7fc4babeda20, GEOSGeom_createEmptyCollection): symbol not found Traceback (most recent call last): File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 333, in startPlugin plugins[packageName] = package.classFactory(iface) File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/__init__.py", line 38, in classFactory return ProcessingPlugin(iface) File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/ProcessingPlugin.py", line 58, in __init__ Processing.initialize() File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/core/Processing.py", line 148, in initialize Processing.addProvider(c()) File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py", line 225, in __init__ from .Polygonize import Polygonize File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/algs/qgis/Polygonize.py", line 28, in from shapely.ops import polygonize File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/ops.py", line 13, in from shapely.geos import lgeos File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/geos.py", line 161, in prototype(_lgeos, geos_version) File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/ctypes_declarations.py", line 162, in prototype lgeos.GEOSGeom_createEmptyCollection.restype = c_void_p File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__ func = self.__getitem__(name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: dlsym(0x7fc4babeda20, GEOSGeom_createEmptyCollection): symbol not found Python version: 2.7.10 (default, Oct 23 2015, 19:19:21) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] QGIS version: 2.18.2 Las Palmas, exported Python Path: /Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing /Applications/QGIS.app/Contents/MacOS/../Resources/python /Users/bwilson/.qgis2/python /Users/bwilson/.qgis2/python/plugins /Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins /Library/Frameworks/SQLite3.framework/Versions/C/Python/2.7 /Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages /Library/Python/2.7/site-packages/scipy-override /Library/Python/2.7/site-packages/numpy-override /Library/Python/2.7/site-packages/matplotlib-override /Library/Frameworks/GDAL.framework/Versions/2.1/Python/2.7/site-packages /Library/Python/2.7/site-packages/PySAL-1.12.0-py2.7.egg /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC /Library/Python/2.7/site-packages /Library/Python/2.7/site-packages/PIL /Users/bwilson/.qgis2//python
What is different? PATH is the same. I might want to change it on both machines to prefer /usr/local/bin/python but that is not the problem.
Building QGIS from source
This is an onerous task... I have not succeeded yet. I want to be able to contribute code changes eventually!
First go do this: Building GDAL on Linux
Then do this based on this page: http://www.qgis.org/api/INSTALL.html#toc3
You don't want to overwrite your custom geos or gdal so this is different than the above link indicates. BTW I am building on Linux Mint 14, not Ubuntu or Debian
I like to break things up into smaller chunks too so I can see what's going on more easily.
# I'd be surprised if you dont already have these sudo apt-get install xauth xfonts-base
# some general tools and development stuff sudo apt-get install bison cmake doxygen flex git pkg-config python-dev python-sip python-sip-dev graphviz xvfb txt2tags sudo apt-get install libfcgi-dev libgsl0-dev libexpat1-dev
# some QT tools sudo apt-get install libqt4-dev libqt4-opengl-dev libqtwebkit-dev libqwt5-qt4-dev pyqt4-dev-tools python-qt4 python-qt4-dev
# some gis things sudo apt-get install libspatialindex-dev libspatialite-dev libsqlite3-dev
- left out because depend on gdal
- libosgearth-dev libopenscenegraph-dev