Self Hosted Leaflet Photo

There is an excellent plugin for Leaflet called Leaflet.Photo.

The plugin was created by Bjørn Sandvik. See the full post:  http://blog.thematicmapping.org/2014/08/showing-geotagged-photos-on-leaflet-map.html

The plugin has a number of examples that show usage with image hosting platforms, like Google Photos and Instagram, which have assicaited API’s for returning information about the image in question.

I was however keen to host the sollution completely myself, so simply have a folder of images that would populate on the map if they had exif GPS information.

I have created an example available on GitHub:

https://github.com/HeikkiVesanto/Leaflet.Photo/tree/gh-pages/local_file_example

Simply download the full repo:

https://github.com/HeikkiVesanto/Leaflet.Photo

Copy the local_file_example folder. Replace the images in the Photos folder with your own photos. Load it onto any php supporting webhost.

Like: BlueHost

Or for more advanced users, the examples below are on: DigitalOcean

And link to the folder with the index.html

Example:

Link.

GIS to CAD using ogr2ogr – Part 3 – Point Annotation to Text in CAD

GIS to CAD using ogr2ogr – Part 1 – Shp to DXF with Contour Data
GIS to CAD using ogr2ogr – Part 2 – GML to DXF with OS MasterMap

MasterMap Topo Sample Data:

https://www.ordnancesurvey.co.uk/business-and-government/licensing/sample-data/discover-data.html

OS MasterMap has an annotation layer, which is simple to symbolise in a GIS program. But becomes more difficult in CAD software.

With ogr2org, when writing a DXF file, if you have an input point geometry, which has an OGR_STYLE attribute, it will be written as a text geometry when opened in CAD.

So for our MasterMap data we have one layer we want to convert to text:
CartographicText

ogrinfo os-mastermap-topography-layer-sample-data.gml CartographicText
OGRFeature(CartographicText):855
fid (String) = osgb1000000729425681
featureCode (Integer) = 10026
version (Integer) = 1
versionDate (String) = 2001-11-11
theme (StringList) = (1:Buildings)
changeDate (StringList) = (1:1999-09-08)
reasonForChange (StringList) = (1:Modified)
descriptiveGroup (StringList) = (1:Buildings Or Structure)
physicalLevel (Integer) = 50
anchorPosition (Integer) = 0
font (Integer) = 2
height (Real) = 1.5
orientation (Integer) = 2890
textString (String) = 5
descriptiveTerm (String) = (null)
make (String) = Manmade
POINT (290875.38 92635.81)

So for this we are primarily interested in “textString” and potentially “orientation”.

Lets see the layer as points first as a baseline:

ogr2ogr -f DXF CartographicText.dxf os-mastermap-topography-layer-sample-data.gml CartographicText

Screenshot[10]

Zoomed in:

Screenshot[11]

But lets try that as text. We will keep this simple and only take into account orientation and to a small extent height. Lets look at orientation:

Orientation – The orientation of text or symbol features for cartographic placement. This is measured in tenths of a degree anticlockwise from due east (0–3599).

So conversion to degree will be simple. Orientation/10

We can also take into consideration height as a multiplier.

And “textString” stores the text itself.

The command:

ogr2ogr.exe -f DXF CartographicText2.dxf os-mastermap-topography-layer-sample-data.gml CartographicText -sql "SELECT 'LABEL(f:""Arial"",s:""'||(height*800)||'"",t:""'||textString||'"",a:""'||(orientation/10)||'"",p:5)' AS OGR_STYLE, * FROM CartographicText" -dialect SQLITE

Full extent:

Screenshot[12]

Zoomed in:

Screenshot[13]

Explained:

Since this is run in windows, through the regular console, the escape character for quotes is two quotes “”‘. So a combination on ‘ ” and “”‘ we can accommodate all the required quotes.

f:””Arial””,s:””‘||(height*800)||'””,t:””‘||textString||'””,a:””‘||(orientation/10)||'””,p:5

f:””Arial””
Font: Arial

s:””‘||(height*800)||'””
Size: Multiplier of the height field, I am not sure what the units are, comments appreciated.

t:””‘||textString||'””
Text: textString column

a:””‘||(orientation/10)||'””
Align: In degrees

p:5
Position: the OS position and the ogr2ogr style position are slightly different, so better placement could be achieved with some pre-processing

GIS to CAD using ogr2ogr – Part 1 – Shp to DXF with Contour Data
GIS to CAD using ogr2ogr – Part 2 – GML to DXF with OS MasterMap

GIS to CAD using ogr2ogr – Part 2 – GML to DXF with OS MasterMap

GIS to CAD using ogr2ogr – Part 1 – Shp to DXF with Contour Data
GIS to CAD using ogr2ogr – Part 3 – Point Annotation to Text in CAD

For this example we are using Ordnance Survey MasterMap Topology Layer data.

MasterMap Topo Sample Data:

https://www.ordnancesurvey.co.uk/business-and-government/licensing/sample-data/discover-data.html

Now we know that we can maintain an attribute through layers, as we saw in the shp to DXF example, the export of MasterMap should be straightforward.

Let’s first see what the GML file contains.

ogrinfo -so os-mastermap-topography-layer-sample-data.gml
Had to open data source read-only.
INFO: Open of 'os-mastermap-topography-layer-sample-data.gml'
using driver 'GML' successful.
1: TopographicArea (Polygon)
2: CartographicText (Point)
3: CartographicSymbol (Point)
4: BoundaryLine (Line String)
5: TopographicPoint (Point)
6: TopographicLine (Line String)

So we have 6 layers in total.

For MasterMap in CAD we will be mainly interested in CartographicText, TopographicPoint, and TopographicLine.

Lets start with TopographicLine.

ogrinfo -so os-mastermap-topography-layer-sample-data.gml TopographicLine

Nothing too useful.

A bit more details:

ogrinfo os-mastermap-topography-layer-sample-data.gml TopographicLine

Sample:

OGRFeature(TopographicLine):185
fid (String) = osgb1000000347615024
featureCode (Integer) = 10019
version (Integer) = 5
versionDate (String) = 2005-03-30
theme (StringList) = (2:Buildings,Land)
accuracyOfPosition (String) = 1.0m
changeDate (StringList) = (4:1994-01-26,2003-11-10,2004-02-19,2005-01-05)
reasonForChange (StringList) = (4:Modified,Attributes,Attributes,Attributes)
descriptiveGroup (String) = Building
physicalLevel (Integer) = 50
physicalPresence (String) = Obstructing
descriptiveTerm (String) = Outline
make (String) = Manmade
nonBoundingLine (String) = (null)
LINESTRING (...)

For this feature the “descriptiveGroup”” seems the most useful, and from reading the os-mastermap-topography-layer-user-guide.pdf the best would be either a combination of descriptiveGroup and descriptiveTerm or using the featureCode. Since this is a simple conversion we will just use a combo of descriptiveGroup and descriptiveTerm to create our DXF layers.

I will be using || for concatenation, which works with the SQlite SQL dialect.

ogr2ogr -f DXF TopographicLine.dxf os-mastermap-topography-layer-sample-data.gml TopographicLine -sql "select descriptiveGroup || ' - ' || descriptiveTerm as Layer from TopographicLine" -dialect SQlite

Result:

layer names ignored in combination with -sql.
ERROR 1: No known way to write feature with geometry 'None'.
ERROR 1: Unable to write feature 0 from layer SELECT.

ERROR 1: Terminating translation prematurely after failed
translation from sql statement.

Not quite. Seems to be missing geometry, perhaps a SQL select issue.

This can be tested with:

ogrinfo os-mastermap-topography-layer-sample-data.gml TopographicLine -sql "select descriptiveGroup || ' - ' || descriptiveTerm as Layer from TopographicLine" -dialect SQLITE

Result:

OGRFeature(SELECT):14634
Layer (String) = Building - Outline

OGRFeature(SELECT):14635
Layer (String) = Building - Outline

So we do not have any geometry. Lets bring that in.

ogr2ogr -f DXF TopographicLine.dxf os-mastermap-topography-layer-sample-data.gml TopographicLine -sql "select descriptiveGroup || ' - ' || descriptiveTerm as Layer, * from TopographicLine" -dialect SQLITE

Geometry looks good:

Screenshot[6]

But if we check the attributes in QGIS:

Screenshot[7]

We can see that all of the attributes that are not 0 have both a descriptiveGroup and a descriptiveTerm, which was not what we can see in the ogrinfo summary. So our SQL statement is cutting some out.

Try again:

ogr2ogr -f DXF TopographicLine2.dxf os-mastermap-topography-layer-sample-data.gml TopographicLine -sql "select descriptiveGroup ||' - '|| coalesce(descriptiveTerm,'') as Layer, * from TopographicLine" -dialect SQLITE

Looking better:

Screenshot[8]

But it won’t open in AutoCAD DWG TrueView. Lets try running it through a ShapeFile format first before the DXF conversion.

ogr2ogr TopographicLine.shp os-mastermap-topography-layer-sample-data.gml TopographicLine -sql "select descriptiveGroup || ' - ' || coalesce(descriptiveTerm,'') as Layer, * from TopographicLine" -dialect SQLITE

ogr2ogr -f DXF TopographicLine3.dxf TopographicLine.shp

Success:

Screenshot[9]

No indication of why a direct GML to DXF conversion would hang TrueView, and your mileage with other CAD software may vary. But ShapeFile is a very simplified geometry format, so perhaps running through that helps with some more complex geometry in the GML. Hard to say with no errors from TrueView, just a stuck program.

Repeat for point:

ogr2ogr -f DXF TopographicPoint.dxf TopographicPoint.shp

ogr2ogr TopographicPoint.shp os-mastermap-topography-layer-sample-data.gml TopographicPoint -sql "select descriptiveGroup || ' - ' || coalesce(descriptiveTerm,'') as Layer, * from TopographicPoint" -dialect SQLITE

GIS to CAD using ogr2ogr – Part 1 – Shp to DXF with Contour Data
GIS to CAD using ogr2ogr – Part 3 – Point Annotation to Text in CAD

GIS to CAD using ogr2ogr – Part 1 – Shp to DXF with Contour Data

GIS to CAD using ogr2ogr – Part 2 – GML to DXF with OS MasterMap
GIS to CAD using ogr2ogr – Part 3 – Point Annotation to Text in CAD

The power of GDAL, and specifically ogr2ogr is pretty impressive. This conversion is from shp to DXF, which is a somewhat universal CAD format so further conversion should be possible.

This post will cover contour export while maintaining 3D elevation, in addition to contour values as layers in CAD. The data used is OS terrain 50.

OS Terrain 50:

https://www.ordnancesurvey.co.uk/opendatadownload/products.html

In QGIS:

Screenshot[1]

Contours in 3D:

ogr2ogr -f DXF contour_zfield.dxf SX99SW_line.shp -zfield PROP_VALUE

With the -zfield creating the 3d elevation.

Great result:

Screenshot[3]

The alternative is to just store the z-value as layers.

ogr2ogr -f DXF contour_layer.dxf SX99SW_line.shp -sql "SELECT PROP_VALUE AS Layer FROM SX99SW_line"

Layers work great:

Screenshot[2]

With the ogr2ogr DXF driver, if you have an input column called “Layer” then it will be used to group features as a layer in DXF. We use a SQL query to achive this. Prop_Value is the height field in my input data.

And putting them all together:

ogr2ogr -f DXF contour_zfield_layer.dxf SX99SW_line.shp -zfield PROP_VALUE -sql "SELECT PROP_VALUE AS Layer FROM SX99SW_line"

Result not as expected, flat output:

Screenshot[4]

Adding our SQL select statement removes our zfield attribute as such ogr2ogr cannot access it. Lets resolve this:

ogr2ogr -f DXF contour_zfield_2_layer.dxf SX99SW_line.shp -zfield PROP_VALUE -sql "SELECT PROP_VALUE AS Layer, * FROM SX99SW_line"

Excellent:

Screenshot[5]

Layers and height.

GIS to CAD using ogr2ogr – Part 2 – GML to DXF with OS MasterMap
GIS to CAD using ogr2ogr – Part 3 – Point Annotation to Text in CAD

UK Rail Network by Agency and Parent

I created a post of the UK rail network some time ago and have been meaning to return to the subject.

This iteration is in Leaflet and will run weekly. The network is generated direcly from the UK rail network timetable file in GTFS format downloaded from: gbrail.info

The network is still generated using a station to station methodology, so the next step will be to incorporate an actual network and run it trough PGRouting. The logic for ownership can be found at: maps.gisforthought.com/uk_rail_map/ukrail_distinct_agencies_parent.html

If there are any issues or inconsistencies, please let me know, preferrably through the GitHub issues page: GitHub Issues

I am very happy with the overall result and all the hosting is done from scratch using a virtual server from: Digital Ocean

A good learning experience with NGINX and mobile forwarding.

As a final warning, the mobile version is not very good, if viewing on mobile and interested, please try on a desktop. Sincere appologies for that. Leaflet may not be the best mobile platform, although it is probably due to my inexperience with it.

Full Page Link

UK Rail Map by Operator and Owner: