Showing posts with label geonames. Show all posts
Showing posts with label geonames. Show all posts

Tuesday, September 15, 2015

Free opensource geocoder and webservices for geonames and openstreetmap data Share on facebookShare on twitterShare on printMore Sharing Services

Free, open source, and ready to use geocoder and geolocalisation webservices

Gisgraphy : Easy geocoding for humans !

Since 2006, Gisgraphy has been a free, open source framework (except the Address parser that is not open source) that offers the ability to do geolocalisation and geocoding via Java APIs or REST webservices. Because geocoding is nothing without data, Gisgraphy provides an easy-to-use importer that will automatically download and import the necessary (free) data to your local database (OpenStreetMapGeoNames and Quattroshapes : more than 100 million entries). You can also add your own data with the Web interface or the import connectors provided. Gisgraphy is production ready, and has been designed to be scalable (load balanced), high performance and is able to be used in other languages other than just Java : results can be output in XML, JSON, PHP, Python, Ruby, YAML, GeoRSS, or Atom. some popular GPS tracking System (OpenGTS or Traccar ) also includes a Gisgraphy client. Gisgraphy is a framework - as a result, it's flexible and powerful enough to be used in a lot of different use cases. read more
Try it ▸▸    Get started ▸▸ 

What's new :

  • Gisgraphy V 4.0 is out! It now manages house numbers, has 100% more data, better relevance, country codes are not required anymore, and SOOOOO much more.
  • Gisgraphy is candidate for the Dataconnexions competition, launched by the French government via the ETALAB mission. The goal is to promote the use of open data and encourage projects that use it.
  • To follow the one version / per year (and after more than one year of development), I am proud to announce that the Version 3.0 of Gisgraphy is now available. It is a major version where a LOT of functionalities have been added. See Why you should update... You can try it here.
  • Read more news

Webservices overview :

All the webservices are world wide (243 countries) and support pagination. Actually, there are 6 (web) services, and all are available for free athttp://services.gisgraphy.com. We also provide some HTML pages that uses the webservices under the hood. Below is a summary for each webservice:
  • Geocoding

    Provide an Address, structured or not, and get it's GPS position in 243 countries.
  • Reverse geocoding 

    Provide a GPS position and get the corresponding address
  • Street search / tracking

    Find streets and associated information for a given GPS point (and an optional name). It is very useful for tracking software like Open GTS or Traccar, but there are a lot of other use cases.
  • Find nearby

    Find places, streets or whatever you want around a GPS point for a given radius. Results can be sorted by distance.
  • Fulltext search / Autocompletion

    For a given text and an optional GPS point, find places, POIS, cities, streets, zip codes,... with information (coordinates, states, population, elevation, alternate names in many languages). Auto completion, location bias, spellchecking, all words required or not...
  • Address parser

    Divide a single address (as a string) into its individual component parts : house number, street type (directional, street, ..), street name, unit (apt, building, ...), zipcode, state, country, city.
Gisgraphoid logoGisgraphoidGisgraphoid is a library to do geocoding on your Android mobile phone or tablet with the same Geocoder API as Google but with Gisgraphy. Runs on all Android versions, free, no Google API needed by the device, no API key, no limit. You can display the result on OpenStreetMap or Google Maps (Google API key required)
leaflet logo Plugins
2 Leaflet plugins are availables to use the webservices directly on a map :Geocoding : It allows you to add a geocoding input with autocompletion on a leaflet map. It wraps the Gisgraphy js API.
 Reverse geocoding : It reverse geocodes when you rightclick on the map. It is an example and you can personalize it.

Openstreetmap data extract by country

Gisgraphy wants to simplify access to the OpeStreetMap data. The model of the OpenStreetMap data is in XML or PBF and is not simple to manage. To simplify this, we have :
  • Extracted all the streets(76 million), cities (4.3 million cities / 216,000 shapes), Points of interest (7 million), and house numbers(34 million) for all 240 countries and put it in a CSV/TSV format.
  • Split the main PBF file for each country.
  • Extracted the shape of more than 160,000 cities and localities from Quatroshapes with their associated geonames Id

All those files are freely available on our download server.. In addition to the native OpenStreetMap data, some pre-calculated fields (length, middle point) are added...Read more

A little bit further...

  • Importers from geonames CSV files. Just give the country(ies) you wish to import and / or the placetypes, and Gisgraphy downloads the files and imports them with all the alternate names (optional) and syncs the database with a fulltext search engine
  • All OpenStreetMap data is processed in CSV format (view data)
  • Importers for OpenStreetMap data in CSV (view data)
  • Importers for Quattroshapes data in CSV (view data)
  • Leaflet plugins
  • WorldWide geocoding / WorldWide reverse geocoding / street search WebServices;
  • REST WebService
  • Several output formats supported : XML, JSON, PHP, Ruby, Python, Atom, RSS / GeoRSS
  • Full text search (based on Lucene / Solr with default filters optimized for city search (case insensitive, separator characters stripping, ..) via an Java API or a webservice
  • Find nearby function (with limits, pagination, restrict to a specific country and/or language and other useful options) via a Java API or a Web Service
  • An admin / back office with statistics interface
  • Fully replicated / scalable / high performance / cached services
  • Search for ZIPcode name, IATA, ICAO
  • Internationalized (with support of Cryllic, Arabic, Chinese,... alphabet)
  • Dojo widgets / prototype / Ajax to ease search but can be use it even if javascript is not enabled on the client side
  • Opensearch module
  • Platform / language independent
  • Provides all the countries flags in svg and png format
  • ...http://www.gisgraphy.com/ https://github.com/gisgraphy/gisgraphy#leaflet-plugins

Geographical information lookup using GeoNames

Geographical information integration is rapidly becoming an integral part of many websites. People use geographic data for a wide variety of applications. From location based content targeting, censoring information by geographic areas to analyzing website traffic by region. It is surprising how much free geographic information is available on the web. GeoNames is one such service.

The GeoNames database

GeoNames is a geographical database released under the creative commons attribution license, that contains over eight million geographical names and consists of 7 million unique features. The data is accessible free of charge through a number of web services and also as a downloadable database, which is updated on a daily basis.
GeoNames integrates geographical data such as names of places in various languages, elevation, population and other geographical information from various sources around the world.
In this post we will see how we can access the GeoNames API with PHP.

Installing the GeoNames API library

GeoNames API is available as a PEAR package, so we will be using the PEAR installer. Run the following command from your console window.
pear install Services_GeoNames-1.0.0
If the installer doexn’t work you can manually download the package fromServices_GeoNames and install it in your PHP includes folder.

Running your first GeoNames search

Now that we have installed the PEAR library, we will start with a small example that will get a list of places by the name ‘London’ and the country where the place is located. You will be surprised how many places the world over are named ‘London’.
<?php
require_once 'Services/GeoNames.php';
 
$geo = new Services_GeoNames();
 
// Search for all cities named 'London'
$cities = $geo->search(array('name_equals' => "London"));
 
foreach ($cities as $city)
{
    // 'name' and 'countryName' are not the only properties
    // available. Do a 'var_dump' on the $city variable to 
    // get other properties.
    printf(" - %s (%s)\n", $city->name, $city->countryName);
}
 
?>
Below is a partial output listing for the above code:
 - London (United Kingdom)
 - London (Canada)
 - London (United States)
 - London (United States)
 - City of London (United Kingdom)
 - London (South Africa)
 - London (South Africa)
 - London (South Africa)
 - London (Philippines)
 - London (Nigeria)
 - London (Switzerland)
.
.
Lets try another API method. The following returns a list of all the countries and its capitals.
<?php
 
require_once 'Services/GeoNames.php';
 
$geo = new Services_GeoNames();
 
// get a list of all countries and capitals
$countries = $geo->countryInfo();
 
foreach ($countries as $country)
{
    printf(" - %s (%s)\n", $country->countryName, $country->capital);
}
 
?>
One of the interesting method in the API is ‘neighbors’, which gets a list of neighbors for a particular country.
<?php
 
require_once 'Services/GeoNames.php';
 
$geo = new Services_GeoNames();
 
// Get a list of neighboring countries of India
$array  = $geo->countryInfo(array('country' => 'IN'));
$cInfo  = $array[0];
 
$neighbours = $geo->neighbours(array('geonameId' => $cInfo->geonameId));
 
foreach ($neighbours as $neighbor)
{
    printf("%s\n", $neighbour->countryName);
}
 
?>
Which outputs the following; the neighbouring countries of ‘India':
Bangladesh
Bhutan
China
Myanmar
Nepal
Pakistan

API function list

There are many methods available in the class for querying various type of geographic data. Below is the complete list of methods available in the API class.
 
array    children()                children(array $params)
array    cities()                  cities(array $params)
stdclass countryCode()             countryCode(array $params)
array    countryInfo()             countryInfo(array $params)
stdclass countrySubdivision()      countrySubdivision(array $params)
array    earthquakes()             earthquakes(array $params)
array    findNearby()              findNearby(array $params)
array    findNearbyPlaceName()     findNearbyPlaceName(array $params)
array    findNearbyPostalCodes()   findNearbyPostalCodes(array $params)
array    findNearbyStreets()       findNearbyStreets(array $params)
stdclass findNearByWeather()       findNearByWeather(array $params)
array    findNearbyWikipedia()     findNearbyWikipedia(array $params)
stdclass findNearestAddress()      findNearestAddress(array $params)
stdclass findNearestIntersection() findNearestIntersection(array $params)
stdclass get()                     get(array $params)
stdclass gtopo30()                 gtopo30(array $params)
array    hierarchy()               hierarchy(array $params)
stdclass neighbourhood()           neighbourhood(array $params)
array    neighbours()              neighbours(array $params)
array    postalCodeCountryInfo()   postalCodeCountryInfo(array $params)
array    postalCodeLookup()        postalCodeLookup(array $params)
array    postalCodeSearch()        postalCodeSearch(array $params)
array    search()                  search(array $params)
array    siblings()                siblings(array $params)
array    weather()                 weather(array $params)
stdclass weatherIcao()             weatherIcao(array $params)
stdclass srtm3()                   srtm3(array $params)
stdclass timezone()                timezone(array $params)
array    wikipediaBoundingBox()    wikipediaBoundingBox(array $params)
array    wikipediaSearch()         wikipediaSearch(array $params)

Performing a generic search

The API provides a general name search which can be helpful if you need to perform some broad query for a search term. Lets take the following example. We use the ‘search’ method to query for the keyword ‘los angeles’. The method takes an array with the query term and the number of results to return. Note that the parameter ‘q’ searches over all attributes of a place : place name, country name, continent, admin codes etc. There are more parameter options besides ‘q’ and ‘maxRows’ which you can use while performing search.
<?php
 
require_once 'Services/GeoNames.php';
 
$geo = new Services_GeoNames();
 
$results = $geo->search(
                        array('q' => "los angeles",
                              'maxRows' => 10)
                        );
 
print_r($results);
 
?>
Below is the first result for the search term ‘los angeles’.
[countryName] => United States
[adminCode1] => CA
[fclName] => city, village,...
[countryCode] => US
[lng] => -118.2436849
[fcodeName] => populated place
[fcl] => P
[name] => Los Angeles
[fcode] => PPL
[geonameId] => 5368361
[lat] => 34.0522342
[population] => 3694820
[adminName1] => California

Using the GeoService API in your applications

Although the API provides a free service, if your are planning to use it in a critical web application, the company provides a commercial option for the same. The advantage of the commercial option is that the web services have higher up-time and fail-over in case of hardware defects or software bugs.
The API allows a limit of 50000 web access per day-per IP, which should be quite enough for most personal projects. Check the limit information here for further details.

Downloading the database

All the information you can gather from the API is also available for download from GeoNames servers in text format. This can be useful if you would like to create your own database for hosting on your servers for data lookup. But bear in mind that the data is frequently updated, so your custom created database will quickly become outdated, which does not happen with the online API. And also you will have to write your own queries for the created database.

Accessing the GeoNames API with jQuery

As an aside you can use the following example code to access the API web-service from javascript using jQuery.
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="data"></div>
 
<script>
 
/* 
  Searches for the keyword 'london', 
  returning a maximum of 5 rows. 
  More information can be found here: 
  http://www.geonames.org/export/geonames-search.html
*/
 
/* 
  Note you need to append 'JSON' to the method 
  name to get the results back in JSON format.
*/  
var apiMethod  = 'searchJSON';
var parameters = 'q=london&maxRows=5';
var result     = '';
 
$.get('http://ws.geonames.org/' + 
      apiMethod + '?' + parameters, function(data) {
 
        $.each(data['geonames'], function(i,item){
           $.each(item, function(j, field){
                result += "(" + j + ") : " + field + "<br/>";
           });
           result += "<br />";
          });
 
$('#data').html(result);          
});
</script>
</body>
</html>
http://www.codediesel.com/libraries/geographical-information-lookup-using-geonames/