OpenEcoMaps – Free Eco-living Maps and Data

OpenEcoMaps provides free eco-living maps and data from OpenStreetMap


OpenEcoMaps

OpenEcoMaps Exeter,UK
But why?

There are lots of community groups, councils and companies out there mapping allotments, renewable energy generators, cycle routes and more. But they all suffer from two shortcomings:

1. Duplication – by putting their work into different places, different maps, we’re duplicating effort and not benefiting from each other’s work. For example, it’s common to find several different people all trying to map food growing spaces in the same part of town. Why not share?
2. Tools – not everybody has the tools to map these things, to put the results onto their web site or provide it to their council in the correct format.

OpenEcoMaps encourages people to share all their data in the same place – OpenStreetMap – and makes it easier for you to make use of the results.
How does it work?

OpenEcoMaps takes the data from OpenStreetMap (published under the Creative Commons Attribution-Sharealike 2.0 license), a community that is mapping the whole world and providing all of the information as open data. It takes a fresh data extract every hour and turns it into reusable KML Files, which can easily be displayed on a map.

Map of Exeter includes:

  • Cycling Map
  • Public Transport
  • Aerial Photography
  • Food growing
  • Zero Waste
  • Sustainable Transport
  • Low Carbon Power

http://www.openecomaps.co.uk/map.php?pack=TTE&zoom=1&lon=-3.51&lat=50.72

Source:
http://tom.acrewoods.net/2011/03/09/growing-pains-getting-data-out-of-openstreetmap/

More information:
http://wiki.openstreetmap.org/wiki/OpenEcoMaps
http://www.openecomaps.co.uk/about.php

Convert, Reproject, and Load Spatial Data to SQL Server with OGR2OGR

I used OGR2OGR to join a set of shapefiles together prior to loading them into SQL Server using Shape2SQL. But OGR2OGR can do much more than simply appending shapefiles – it can convert data into different formats, transform coordinates into different spatial references systems, read and write a whole variety of spatial datasources, and (with a bit of fiddling) load them into SQL Server 2008.

To demonstrate, I thought I’d repeat the objective of my previous post, but instead of simply appending the Ordnance Survey open data shapefiles together, I would reproject them into a different SRID, and import them into SQL Server too using OGR2OGR alone, without using Shape2SQL or any other tools.

Use OGR2OGR to create a CSV file containing WKT

OGR2OGR can’t insert spatial data directly into SQL Server 2008, but it can create CSV files that can be read into SQL Server. To create an output file in CSV format, set the –f CSV output option. You can also manually set layer creation options to dictate the field delimiter and line return character of the CSV file, using the LINEFORMAT and SEPARATOR layer creation options.

By default, the CSV file created only contains columns containing the attributes associated with each shape (i.e the data in the .dbf file associated with a shapefile), but it doesn’t include the shape itself. To include the shape of the geometry in Well-Known Text format, you also need to state the –lco “GEOMETRY=AS_WKT” layer creation option.

But that’s not all – OGR2OGR can also reproject data between coordinate systems as it converts it. To convert to another spatial reference system, include the -t_srs parameter, together with either the full WKT definition (hard to escape properly,i.e. GEOGCS(ELLIPSOID(“WGS 84”, ……) or the EPSG code (much easier, i.e. EPSG:4326 for WGS84).

Putting this all together, you can use the following command to load a shapefile (in this case, the Ordnance Survey OS Vector Map settlement_area polygon shapefile), reproject the data into SRID 4326, and then save the result as a CSV file containing a column with the WKT of each resulting polygon:
[php]ogr2ogr -f "CSV" "Settlement_Area" "Settlement_Area.shp" -t_srs "EPSG:4326" -lco "GEOMETRY=AS_WKT" -lco "LINEFORMAT=CRLF" -lco "SEPARATOR=SEMICOLON" [/php]
NOTE – I’ve noticed some problems with the quote/speechmark characters in this blog being changed to “smartquotes”, even when I use the code-formatting option. OGR2OGR isn’t happy about this, so I recommend that you don’t try and copy and paste the line above into a CMD window – if you get an error about “Couldn’t fetch request layer uT” or something similar then be sure to retype using normal speech marks.

More information on CSV options for OGR2OGR can be found here: http://www.gdal.org/ogr/drv_csv.html

Create a Format File

To import the CSV into SQL Server, we have a range of options – you could use SSIS, or you could use the Tasks –> Import Data wizard. Or you could use BCP or BULK INSERT. However, I’m going to use OPENROWSET. This will allow me to write a single query to access the CSV file directly from T-SQL as if it were an existing table.

In order to do this, we first need to define a format file which specifies the datatypes of each of the columns in the input csv file, and how they should be mapped to datatypes of columns in a sql table. More information on format files can be found here.

The following shows the XML format file required for the OS VectorMaps Settlement Area shapefile just converted:

[php]<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="0" xsi:type="CharTerm" TERMINATOR="""/>
<FIELD ID="1" xsi:type="CharTerm" MAX_LENGTH="2147483647" TERMINATOR="";"/>
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR=";"/>
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR="\r\n"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="WKT" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="2" NAME="FEATCODE" xsi:type="SQLDECIMAL"/>
<COLUMN SOURCE="3" NAME="FEATDESC" xsi:type="SQLVARYCHAR"/>
</ROW>
</BCPFORMAT>
[/php]
Query the CSV from SQL Server using the Format File

Finally, you can write a SELECT query in SQL Server to query the CSV file using  OPENROWSET in conjunction with the format file above. Since the CSV contains column headers, I’ve included the FIRSTROW=2 parameter to skip the header row. I’ve also used the geometry::Parse() method in the SELECT to dynamically create the geometry data from the Well-Known Text representation contained in the WKT column of the supplied CSV file.
[php]SELECT
FEATCODE,
FEATDESC,
geography::Parse(WKT)
FROM OPENROWSET(
BULK ‘C:Settlement_Area.csv’,
FORMATFILE=’C:Settlement_Area_format_file.xml’,
FIRSTROW = 2
) AS CSV;[/php]
And here’s the results showing my Ordnance Survey data, originally provided as a shapefile using projected coordinates in SRID 27700, now loaded as latitude/longitude coordinates (EPSG:4326) using the geography datatype:

image

Barton on Daring Belief

“Nothing splendid has ever been achieved except by those who dared believe that something
inside themselves was superior
to circumstance.”

–Bruce Barton (1886–1967)

American advertising executive

U.S. congressman

“Diligence is the mother of good luck.”

– Benjamin Franklin (1706–1790)

American statesman, scientist, and printer

luck: noun: a force that makes things happen

You want more luck? Be the force that makes it happen…

  1. Prepare. Work hard to be ready for the opportunities that are important to you. Research. Practice. Perfect.
  2. Be awake. Pay attention to the people, events, and things around you. Evaluate logically and trust your gut instinct.
  3. Take action. Put yourself out there. Explore. Be vulnerable. Make contact with people. Take risks.
  4. Expect positive results. Optimism improves your chances. If (when) you fail, embrace the lesson and continue on, smarter.

That’s it. Now go be lucky (and sell something).