Comments (7)
I looked into the " d = QgsDistanceArea()" line, thinking maybe the constructor is setting a default CRS of WGS 84 all the time (http://qgis.org/api/qgsdistancearea_8cpp_source.html#l00047). Turns out it is doing this. But when I add a line or two of code to set the source CRS of "d" to a different projected CRS, I am still getting the small measurements...
from chinese-postman.
I have also been fighting with these CRS settings for so long that I had to write down the steps to make it work correctly. Here is my current workflow.
I found that simply changing the project CRS did not work. The only way I got it to work is by saving it as a Shapefile with the right CRS and re-import that (step 3 below).
In the end there are way too many steps involved now, so please tell me if you have some improvements.
1. Export map from OpenStreetMap.org
From openstreetmap.org, export area and save the .osm somewhere.
2. Import map into QGIS
Project -> New
Vector -> OpenStreetMap -> Import Topology from XML...
OK + Close
In side-pane Browser, press Refresh
Vector -> OpenStreetMap -> Export Topology to SpatiaLite...
Export type: Polylines (open ways)
Exported tags -> Load from DB -> Check all boxes
[v] Load into canvas when finished
OK + Close
In side-pane Browser, press Refresh
3. Save layer as Shapefile with different CRS
In side-pane Layers, right-click on the layer -> Properties -> General
Coordinate Reference System should say EPSG: 4326, WGS 84. This is the CRS used by OpenStreetMap.
OK
Again right-click on the layer -> Save as...
Format: ESRI Shapefile
CRS: Selected CRS
Click on the small icon on the right to select a CRS. Select a Projected Coordinate System. For example, for maps in Europe:
Projected Coordinate Systems -> Equidistant Conic -> Europe_Equidistant_Conic EPSG:102031
Keep the other settings as they were:
Encoding: System
[ ] Save only selected features
[ ] Skip attribute creation
[v] Add saved file to map
Symbology export: No symbology
[ ] Extent (current: layer)
OK
In side-pane Layers, right-click on the new layer -> Set Project CRS from Layer
In the bottom right of the screen, the CRS should now show EPSG:102031. Coordinates should look like -300000,2500000, not like 4.5000,50.0000.
Right-click on the old layer -> Remove.
http://gis.stackexchange.com/questions/35590/how-to-reproject-a-vector-layer-in-qgis
http://manual.linfiniti.com/en/vector_analysis/reproject_transform.html
http://docs.qgis.org/2.8/en/docs/training_manual/vector_analysis/reproject_transform.html
http://gis.stackexchange.com/questions/52004/how-to-convert-coordinates-in-a-csv-into-another-crs-in-qgis
https://www.reddit.com/r/gis/comments/2vo8e8/how_can_i_convert_these_state_plane_numbers_to/
4. Use Google Maps-like display style (optional)
In side-pane Layers, right-click on the polylines layer -> Properties.
Style -> Style -> Load style... -> Load from file
Select the downloaded osm_spatialite_googlemaps_lines.qml
OK
5. Clean up all unwanted elements
(Note that deleting elements from a layer seems to remove them from the Shapefile on which the layer is based.)
Remove all elements that are not part of the post route.
To see a complete list of elements:
Right-click on layer -> Open Attribute Table.
6. Re-add original layer
In side-pane Browser -> SpatiaLite -> double-click on the table created in Step 2 to add it as a new Layer. It will be in the wrong CRS, but if on-the-fly (OTF) CRS transformation is on, it will still be visible.
This way, you can see the original map as a background of the routes.
Using chinese-postman
See https://github.com/rkistner/chinese-postman/blob/master/Readme.md#usage-in-qgis
Optional roads
Optional roads are not possible. Instead, try making multiple calculations with the optional roads selected or not.
Save memory layer as Shapefile
The chinese_postman route is a memory layer, which is lost when closing QGIS.
In side-pane Layers, right-click on the new chinese_postman layer.
Save as...
[v] Add saved file to map
The line style (line with arrows) is not saved in the Shapefile (see below). It will be saved in the project though, or you can save it to a .qml before quitting and then loading it later:
In side-pane Layers, right-click on the new chinese_postman layer.
Style -> Style -> Save style -> QGIS Layer Style File
And then when you need it again later:
Style -> Style -> Load style... -> Load from file
The Shapefile of the Chinese postman route should have been added as a new layer in the project already. Now the 'chinese_postman' memory layer can be deleted.
from chinese-postman.
Btw, perhaps you better open a separate issue for discussing a possible Windy Chinese Postman feature.
from chinese-postman.
Thank you!
I have tried your steps with no improvement unfortunately... Although, I did skip 4, 5, and 6 - those do not seem related to CRS or measurement, or are those required? What version of QGis are you using?
QGIS version
2.12.1-Lyon
When I use the GUI Measure Line tool before doing any of your steps (OSM in WGS 84), I get accurate measurements (but Chinese Postman is inaccurate). Afterwards, even this tool, in addition to Chinese Postman, gives me very small numbers - centimeters over what are really kilometers. I used an Equidistance Conic projection (USA) like you.
Isn't "QgsDistanceArea.measureLine" supposed to transform coordinates and calculate a result in meters anyway? http://qgis.org/api/qgsdistancearea_8cpp_source.html#l00488. I tried passing a third argument for units as shown for the method there but python complains about the extra argument.
I may just give up at this point... This is a great tool though, and I can export the route as a GPX file and upload to any number of websites or applications to get a distance.
from chinese-postman.
Never mind, I think I got it working! Only difference, I think, was downloading from OSM themselves rather than using this - http://www.openstreetmap.re/osm2gis/. Anyway, thanks so much, glad I finally got a number in the right units after like 10 man-hours, haha!!!
from chinese-postman.
Great. You were right that only steps 1 through 3 are needed for the right measurements.
As you said, the QGIS GUI measurement tool is more forgiving, but judging by the information it shows in the Info part of its Measure window, it also seems to have some more intelligence built in for that purpose.
Anyway, glad you got it working. Good luck!
from chinese-postman.
I'm on QGIS 2.8.4 (Wien), btw.
from chinese-postman.
Related Issues (18)
- failed by: AttributeError: 'generator' object has no attribute 'sort' HOT 3
- Incompatible with QGIS 2 HOT 7
- icon.png HOT 4
- No module named resources HOT 1
- Windy Chinese Postman HOT 2
- Turn-by-Turn? HOT 2
- Error: Could not find any components. Try selecting different features. HOT 2
- Error postman.py HOT 1
- Inaccurate results for trivial problems HOT 4
- AttributeError: 'set' object has no attribute 'items' HOT 2
- cant export from qgis HOT 2
- AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs' HOT 8
- Unable to install plugin in QGIS 3.14.0-Pi HOT 1
- "Chinese Postman Solver" not found in QGIS plugin manager. HOT 5
- Tips for using the Chinese Postman plugin HOT 1
- AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs' HOT 12
- Cannot import gcd from fractions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chinese-postman.