tag:blogger.com,1999:blog-41304228771072199912024-03-12T19:58:04.588-07:00Useful Practical GeoBlogThe Creasehttp://www.blogger.com/profile/12006191009546481981noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-4130422877107219991.post-62791149163610204372014-11-12T05:38:00.000-08:002014-11-12T05:40:06.430-08:00Is Fiona being difficult?I had installation problems with fiona. I tried first the easy route :<br />
<br />
<pre style="background-color: #f7f7f7; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; font-stretch: normal; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;"><span style="line-height: 1.45;">$ </span><span style="color: black; font-family: Times; font-size: small; line-height: normal; white-space: normal;">brew install gdal</span></pre>
<pre style="background-color: #f7f7f7; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; font-stretch: normal; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;"><span style="line-height: 1.45;">$ </span><span style="color: black; font-family: Times; font-size: small; line-height: normal; white-space: normal;">pip install fiona</span></pre>
<br />
BUT, installing fiona could not find the gdal library. So, I tried the alternative route<br />
<br />
<pre style="background-color: #f7f7f7; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; font-stretch: normal; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;">$ git clone git://github.com/Toblerity/Fiona.git
$ cd Fiona
$ python setup.py build_ext -I/path/to/gdal/include -L/path/to/gdal/lib -lgdal ins</pre>
I had installed the Kyngchaos pre-built version of GDAL previously, so this had placed the headers and libs in the wrong place. So I added them in to the -I and -L arguments...should work, but it did not....still not.<br />
<br />
Then, I chanced upon the reason. My PATH contained the link to the kyngchaos location (/Library/Frameworks/GDAL.framework/Programs), and this seemed to override all the arguments (-I & -L). So, I removed it from my path and added the expected location usr/local/bin (where brew places the gdal-config file). And it worked.....<br />
<br />The Creasehttp://www.blogger.com/profile/12006191009546481981noreply@blogger.com0tag:blogger.com,1999:blog-4130422877107219991.post-60142636708517618542013-04-07T22:39:00.004-07:002013-04-07T22:39:56.716-07:00Android Bug - SolutionIf, whilst building and deploying an Android app, the following error rears it´s unwanted head in the console - INSTALL_PARSE_FAILED_NO_CERTIFICATES, then many solutions exist on the web. None of them worked for me in isolation!!! In the end I had to combine two of them, - change a filename in the res folder AND then delete the bin folder (to force a re-build). then change the filename back to what it was called before. Then this error disappeared........<br />
<br />
<br />The Creasehttp://www.blogger.com/profile/12006191009546481981noreply@blogger.com1tag:blogger.com,1999:blog-4130422877107219991.post-60653010193528708952013-03-28T04:42:00.003-07:002013-04-07T22:41:41.824-07:00Importing OSM data to PostGIS 2.0This is a note for myself, and details the lessons I have learned whilst trying to load an .osm file into a PostGIS 2.0 database.<br />
<br />
1. don´t use osmosis, due to the fact it seems to be rarely updated and suffers from this problem which I could not solve - http://wiki.openstreetmap.org/wiki/64-bit_Identifiers.<br />
<br />
2. osm2pgsql is much better, but for it to work with PostGIS 2.0 I had to rename the "st_astext(geometry)" function to "astext(geometry)" as otherwise it throws an error. (the old filename refers to a previous version of Postgis that used different naming conventions)<br />
<br />
3. despite using the --password and -W flag, the postgis datbase threw an error as it required the password. Therefore I had to change the 'md5' permission for a local user to 'trust' so that no password was necessary in the pg_hba.conf file.<br />
<br />
4. I had to paste the following code in SQL to create an operator that was missing in the PostGIS 2.0 distribution<br />
<br />
<br />
CREATE OPERATOR CLASS gist_geometry_ops<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>FOR TYPE geometry USING GIST AS<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>STORAGE box2df,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 1 << ,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 2 &<<span class="Apple-tab-span" style="white-space: pre;"> </span> ,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 3 && ,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 4 &><span class="Apple-tab-span" style="white-space: pre;"> </span> ,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 5 >><span class="Apple-tab-span" style="white-space: pre;"> </span> ,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 6 ~=<span class="Apple-tab-span" style="white-space: pre;"> </span> ,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 7 ~<span class="Apple-tab-span" style="white-space: pre;"> </span> ,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 8 @<span class="Apple-tab-span" style="white-space: pre;"> </span> ,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 9 &<| ,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 10 <<| ,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 11 |>> ,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 12 |&> ,<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 13 <-> FOR ORDER BY pg_catalog.float_ops,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OPERATOR 14 <#> FOR ORDER BY pg_catalog.float_ops,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>FUNCTION 8 geometry_gist_distance_2d (internal, geometry, int4),<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>FUNCTION 1 geometry_gist_consistent_2d (internal, geometry, int4),<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>FUNCTION 2 geometry_gist_union_2d (bytea, internal),<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>FUNCTION 3 geometry_gist_compress_2d (internal),<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>FUNCTION 4 geometry_gist_decompress_2d (internal),<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>FUNCTION 5 geometry_gist_penalty_2d (internal, internal, internal),<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>FUNCTION 6 geometry_gist_picksplit_2d (internal, internal),<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>FUNCTION 7 geometry_gist_same_2d (geom1 geometry, geom2 geometry, internal);The Creasehttp://www.blogger.com/profile/12006191009546481981noreply@blogger.com0tag:blogger.com,1999:blog-4130422877107219991.post-23297012328583827292012-09-02T02:10:00.002-07:002012-09-02T02:17:56.438-07:00Updated GeoTools Routing Example<br />
I have updated the code example for the GeoTools routing that I had earlier on this blog. You can find the code and example datasets below<br />
<br />
https://sites.google.com/site/usefulpracticalgeoblog/home/routecalculationexample.<br />
<br />
<div style="text-align: justify;">
<b>Route_Example_GeoTools.zip</b> is the latest code example. It contains a folder with the necessary Java classes and two .shp files. One file contains the network dataset for Vienna, Austria (available from http://www.geofabrik.de/data/shapefiles.html), the other contains two destinations for the example code. It requires Geotools 2.7 libraries to run. I have tried to comment it heavily to make it clear. It uses only the distance information to calculate the weights of the edges, but that can easily be changed to incorporate anything else, such as travel time etc. This code example calculates the route from one origin to two destinations (green points on screenshot below).</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Here is a screenshot of the output :</div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-n6Z3TBav_50/UEMjlckngwI/AAAAAAAAB-g/l3d0IdIih2A/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="265" src="http://3.bp.blogspot.com/-n6Z3TBav_50/UEMjlckngwI/AAAAAAAAB-g/l3d0IdIih2A/s320/Capture.PNG" width="320" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
The Creasehttp://www.blogger.com/profile/12006191009546481981noreply@blogger.com5tag:blogger.com,1999:blog-4130422877107219991.post-68544469744050140842012-08-31T05:36:00.001-07:002012-08-31T05:40:21.772-07:00 Ghostly GTFS Skyscraper<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-xhaI8LvGmqY/UECuyQdwj2I/AAAAAAAAB-I/bE2B13hgbgg/s1600/madrid.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="http://3.bp.blogspot.com/-xhaI8LvGmqY/UECuyQdwj2I/AAAAAAAAB-I/bE2B13hgbgg/s320/madrid.png" width="320" /></a></div>
This is not some ghostly skyscraper but a collection of all the space-time paths from the public transport system in Madrid for a single day (z = time of the day). Click on the picture itself for a larger version. I am working on some code that can eventually calculate the areas of spatio-temporal accessibility (travel time isolines) from point locations using the original (General Transit Feed Specification) GTFS data. This is the first step I guess....The Creasehttp://www.blogger.com/profile/12006191009546481981noreply@blogger.com0tag:blogger.com,1999:blog-4130422877107219991.post-51239274939661680482012-08-31T03:36:00.001-07:002012-08-31T04:49:44.732-07:00GeoSimple Data Free For All!!!<br />
<br />
If anyone is looking for a comprehensive places dataset, then try the open sourced SimpleGeo database dump (see link below)<br />
<br />
<a href="http://archive.org/details/2011-08-SimpleGeo-CC0-Public-Spaces">http://archive.org/details/2011-08-SimpleGeo-CC0-Public-Spaces</a><br />
<br />
<br />
From SimpleGeo: "<i>We’re very excited to announce that the SimpleGeo’s CC0 Places data set is now available for download at no cost. If you’d like to get your hands on 21M+ POIs that cover 63 countries, we’re ready to hand that over to you in one file. The file is about 2GB in .ZIP format, and remember, with the CC0 license, this data becomes yours – free and clear – to do whatever you want.</i>"<br />
<br />
<br />
It holds 21 million of places!!!, but with a horrible geo-json format, probably pumped out of a NoSQL database. Therefore, I have created a couple of Java classes that export it to a friendlier CSV file. First run the Clean_Geojson.java class to produce a more easily parsed file, and then run ConvertToCSV.java on the file output by the cleaning process. As the files are huge, this process avoids storing everything in memory (which may cause your JVM to become unhappy with its Heap size).<br />
<br />
<a href="https://sites.google.com/site/usefulpracticalgeoblog/home/jai">https://sites.google.com/site/usefulpracticalgeoblog/home/jai</a><br />
<div>
<br /></div>
<div>
On first look, it is more complete than any other place dataset that I have come across. Even beats OSM here in Zürich, which up until now was perhaps the best open source dataset of places.</div>
<div>
<br /></div>
<div>
NOTE : requires the google JSON java parser, available here <a href="http://code.google.com/p/google-gson/downloads/list">http://code.google.com/p/google-gson/downloads/list</a><br />
<br />
<br /></div>
The Creasehttp://www.blogger.com/profile/12006191009546481981noreply@blogger.com0tag:blogger.com,1999:blog-4130422877107219991.post-57817264424302125542011-03-03T05:05:00.000-08:002012-09-02T02:19:03.075-07:00GeoTools Route CalculationEDIT: THIS POST HAS BEEN REPLACED BY THE MORE RECENT BLOG POST FOUND HERE<br />
<a href="http://usefulpracticalgeoblog.blogspot.ch/2012/09/geotools-routing.html">http://usefulpracticalgeoblog.blogspot.ch/2012/09/geotools-routing.html</a><br />
<br />
<strike>Java Classes to calculate network distances between an origin and several destinations. Uses Geotools 2.7 library and JAI library, details of where to download them can be found in the Main class. Takes as input ESRI shapefiles for the network and destinations and outputs either a FeatureSource containing the routes and associated costs or just an arraylist of costs (which is here the euclidean distance) and objectIDs.</strike><br />
<strike><br /></strike>
<a href="https://sites.google.com/site/usefulpracticalgeoblog/home/routecalculationexample"><strike>https://sites.google.com/site/usefulpracticalgeoblog/home/routecalculationexample</strike></a><br />
<strike><br /></strike>
<strike>Also included are the two shapefiles for use with the example Main Class. When used on other datasets make sure the CRS and SRID values reflect the datasets to which they are applied, otherwise I imagine an error frenzy will ensue :-)</strike>The Creasehttp://www.blogger.com/profile/12006191009546481981noreply@blogger.com3tag:blogger.com,1999:blog-4130422877107219991.post-18800740317553821272010-11-16T01:54:00.000-08:002010-11-16T02:08:33.153-08:00Installing PostGIS with Tomcat - Important Reminder<h3><span class="Apple-style-span" style="font-size: medium; font-weight: normal;">Copy the Postgres JDBC jar to $CATALINA_HOME/common/lib (This is the wrong path for my tomcat installation, i used </span><span class="Apple-style-span" style="font-size: medium;">Apache Software Foundation\apache-tomcat-6.0.26\lib</span><span class="Apple-style-span" style="font-size: medium; font-weight: normal;"> instead). As with Oracle, the jars need to be in this directory in order for DBCP's Classloader to find them. This has to be done regardless of which configuration step you take next.</span></h3><br />
Taken from :<br />
<a href="http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html#PostgreSQL">http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html#PostgreSQL</a><br />
<br />
Without this the class will give a no class found error :-)<br />
<br />
And here is a Hello World taken form<br />
<br />
<a href="http://www.fankhausers.com/postgresql/jdbc/#hello">http://www.fankhausers.com/postgresql/jdbc/#hello</a><br />
<br />
<br />
<a href="" name="hello"></a><br />
<h3><a href="" name="hello">HelloPostgresql.java</a></h3><pre>/**
* A demo program to show how jdbc works with postgresql
* Nick Fankhauser 10/25/01
* nickf@ontko.com or nick@fankhausers.com
* This program may be freely copied and modified
* Please keep this header intact on unmodified versions
* The rest of the documentation that came with this demo program
* may be found at http://www.fankhausers.com/postgresql/jdbc
*/
import java.sql.*; // All we need for JDBC
import java.text.*;
import java.io.*;
public class HelloPostgresql
{
Connection db; // A connection to the database
Statement sql; // Our statement to run queries with
DatabaseMetaData dbmd; // This is basically info the driver delivers
// about the DB it just connected to. I use
// it to get the DB version to confirm the
// connection in this example.
public HelloPostgresql(String argv[])
throws ClassNotFoundException, SQLException
{
String database = argv[0];
String username = argv[1];
String password = argv[2];
Class.forName("org.postgresql.Driver"); //load the driver
db = DriverManager.getConnection("jdbc:postgresql:"+database,
username,
password); //connect to the db
dbmd = db.getMetaData(); //get MetaData to confirm connection
System.out.println("Connection to "+dbmd.getDatabaseProductName()+" "+
dbmd.getDatabaseProductVersion()+" successful.\n");
sql = db.createStatement(); //create a statement that we can use later
String sqlText = "create table jdbc_demo (code int, text varchar(20))";
System.out.println("Executing this command: "+sqlText+"\n");
sql.executeUpdate(sqlText);
sqlText = "insert into jdbc_demo values (1,'One')";
System.out.println("Executing this command: "+sqlText+"\n");
sql.executeUpdate(sqlText);
sqlText = "insert into jdbc_demo values (3,'Four')";
System.out.println("Executing this command twice: "+sqlText+"\n");
sql.executeUpdate(sqlText);
sql.executeUpdate(sqlText);
sqlText = "update jdbc_demo set text = 'Three' where code = 3";
System.out.println("Executing this command: "+sqlText+"\n");
sql.executeUpdate(sqlText);
System.out.println (sql.getUpdateCount()+
" rows were update by this statement\n");
System.out.println("\n\nNow demostrating a prepared statement...");
sqlText = "insert into jdbc_demo values (?,?)";
System.out.println("The Statement looks like this: "+sqlText+"\n");
System.out.println("Looping three times filling in the fields...\n");
PreparedStatement ps = db.prepareStatement(sqlText);
for (int i=10;i<13;i++)
{
System.out.println(i+"...\n");
ps.setInt(1,i); //set column one (code) to i
ps.setString(2,"HiHo"); //Column two gets a string
ps.executeUpdate();
}
ps.close();
System.out.println("Now executing the command: "+
"select * from jdbc_demo");
ResultSet results = sql.executeQuery("select * from jdbc_demo");
if (results != null)
{
while (results.next())
{
System.out.println("code = "+results.getInt("code")+
"; text = "+results.getString(2)+"\n");
}
}
results.close();
sqlText = "drop table jdbc_demo";
System.out.println("Executing this command: "+sqlText+"\n");
sql.executeUpdate(sqlText);
db.close();
}
public static void correctUsage()
{
System.out.println("\nIncorrect number of arguments.\nUsage:\n "+
"java <database> <user> <password>\n");
System.exit(1);
}
public static void main (String args[])
{
if (args.length != 3) correctUsage();
try
{
HelloPostgresql demo = new HelloPostgresql(args);
}
catch (Exception ex)
{
System.out.println("***Exception:\n"+ex);
ex.printStackTrace();
}
}
}
</password></user></database></pre><div><database><user><password><br />
</password></user></database></div>The Creasehttp://www.blogger.com/profile/12006191009546481981noreply@blogger.com0tag:blogger.com,1999:blog-4130422877107219991.post-82107430677457068642010-10-25T02:53:00.000-07:002010-10-25T02:53:43.805-07:00First BlogThis blog will be used to store information that I commonly have forgotten or will forget in the future e.g. installing servers, developing web map servers etc etc etc. I guess it is a form of mnemonic that gets knowledge out of my head into the digital world. The question is how long will it last before I forget about the blog??? I reckon four months at the most but we will see.The Creasehttp://www.blogger.com/profile/12006191009546481981noreply@blogger.com0