Mapperz's answer is invalid. Sinus must be calculated from latitude and NOT from longitude.
So corect SQL statement is:
3959 * acos (
cos ( radians(78.3232) )
* cos( radians( lat ) )
* cos( radians( lng ) - radians(65.3234) )
+ sin ( radians(78.3232) )
* sin( radians( lat ) )
) AS distance
The SQL statement that will find the closest 20 locations that are within a radius of 30 miles to the 78.3232, 65.3234 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude, and then asks for only rows where the distance value is less than 30 miles, orders the whole query by distance, and limits ...
Ok, this is hilarriuusss. I tracked this down. In an old copy of lwgeom/lwgeom_spheroid.c in PostGIS 1.0.0rc4 you can see this,
* This algorithm was taken from the geo_distance function of the
* earthdistance package contributed by Bruno Wolff III.
* It was altered to accept GEOMETRY objects and return results in
There is simple query for this case.
SELECT a.id AS store,count(b.*) AS customer_count FROM stores a, customers b
WHERE ST_DWithin(a.geom::geography,b.geom::geography,5000) GROUP BY a.id
I have stored my sample data in the projection WGS 84 (4326). When you want to use a metric system, you have to convert the geometries to geography format.
Based on your descriptions, you don't need a GIS as much as you need the data. You said it yourself: You'd have to track down administrative border data and census data. (If you let us know which area of the world you need, we might be able to offer guidance.)
The GIS functionality mentioned so far is limited to simple "Identify" operations in a web map. I ...
If you are using MySQL 5.6.1+, take a look at ST_Contains.
Given table called points and polygons, with a primary key called id and a geometry column called geometry, this should work:
SELECT points.id FROM polygons, points WHERE ST_CONTAINS(polygons.geom, points.geom);
If there's no geometry column for the points table, but there are latitude and ...
SELECT s.name, s.type, ST_Distance(s.geom, p.geom) As distance, s.geom
FROM shops s, people p
WHERE p.name = 'tom' AND s.type = 'butcher'
AND ST_Intersects(s.geom, ST_Buffer(p.geom, 500))
ORDER BY distance;
One note, this assumes that both layers are in the same projection, and that projection can't just be lat/long or you'll need to use ST_Transform ...
The only plugins I know that involve databases in QGIS are:
SQL Anywhere plugin
You can also import MySQL layers directly via:
Layer > Add Vector Layer... > select Database and your type.
MySQL should be following the WKT specification that was detailed by the Open Geospatial Consortium's Simple Feature Access - Part 1: Common Architecture.
The text you have is not valid WKT, and no GIS software will accept it (generally it will raise a parse error). Commas are used to separate coordinates and spaces between components of each coordinate. ...
You cannot legally cache or store results from Google's Map API (with pretty narrow exceptions).
From the Terms of Service (with emphasis added):
10.1.3 Restrictions against Data Export or Copying.
(b) No Pre-Fetching, Caching, or Storage of Content. You must not
pre-fetch, cache, or store any Content, except that you may store: (i)
The actual answer is a mixture of the other answers/comments you've already received.
MySQL is limited
I see from the tags you're using MySQL, the problem is, it can only do bounding boxes until 5.6, not the actual geometries. http://dev.mysql.com/doc/refman/5.0/en/spatial-relation-functions.html
If you want to use the bounding box:
Your assumption is pretty much correct. MySQL's spatial support is ... simplistic to say the least. It does work, but you'll find very few GIS applications support it. This isn't specific to just polygons, any spatial feature is more limited in MySQL because while it does store them in the same way (WKB), there simply aren't as many functions to manipulate ...
I had the same issue. Try this, worked for me:
$geojson = array(
'type' => 'FeatureCollection',
'features' => array()
and change the array_push to:
The first question is to decide why you want to move to a noSql database. Moving just because its the new way of doing things may not be your best option. The first thing to decide is what a noSql database gives you that traditional Sql can't. I would suggest that for a vehicle tracking system the answer is not a lot.
I would probably stick with Sql but ...
From QGIS 2 advanced changelog you can read :
Feature: Save styles in your database
If you are using a database vector data store, you can now store the layer style definitions directly in the database. This makes it easy to share styled layers in an enterprise or multi-user environment.
(source : http://changelog.linfiniti.com/version/1/)
It works for ...
It doesn't look like it is included in the most recent GDAL-Complete framework. Please file a request with kyngchaos.com.
In the meantime, if you don't mind trying it yourself, you can attempt to build a shared plugin for GDAL 1.10, install it, and see if it works with your data source:
Ensure you have XCode and/or its command line tools installed.
Postgis is an extension to Postgres, rather than a stand alone application, that provides a spatial data type to Postgres, and provides numerous spatial functions that operate on geometry(ies). Spatial indexing, which you will surely need to find n closest points efficiently, is implemented as an extended R-tree, but the indexing mechanism comes from ...
OK, so the main struggle (and obvious error) is the newbie mistake of not controlling which code runs in PHP in the server, which code runs in JS in the browser, and not having control over which variable holds what.
Seriously, read that. If you copy-paste my code, the stackoverflow gods ...
This is fixed in Mapserver-7.0.3 and backported to other versions (6.0.5, 6.2.3, 6.4.4). Looks like Kain's question was taken as a bug report which was subsequently fixed. See OGR error messages too verbose .
While the geohash representation is convenient, it is not designed with spatial queries in mind. From my understanding of the Geohash algorithm you can't just select all the points inside a given bounding box by simple string comparison.
This image might help understanding it a bit better:
(image from http://www.movable-type.co.uk/scripts/geohash.jpg)
Quoting from the GDAL documentation for the Esri Shapefile driver:
An attempt is made to read the LDID/codepage setting from the .dbf
file and use it to translate string fields to UTF-8 on read, and back
when writing. LDID "87 / 0x57" is treated as ISO8859_1 which may not
be appropriate. The SHAPE_ENCODING configuration option may be used to
In a nutshell, you need to use a projection library. PostGIS uses one (PROJ.4), but MySQL doesn't.
The "ST_Distance_Sphere" like functions are much easier to implement, since the math is simpler (see Great-circle distance formulas, or other good examples). The "ST_Distance_Spheroid" like functions are more accurate (the shape of the earth is closer to a ...
Each data provider has its URI and its provider key. Once added via User Interface, it's easy to collect them and use them from the console.
Enter this statement in your python console, to collect the URI and key for all map layers:
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
uri = layer.dataProvider().dataSourceUri()
What is the purpose of the application? To give advice on what NoSQL database to use that is necessary information. For instance:
1) Do you need ACID transactions?
2) What is the ratio between R/W?
3) Throughput (how many R/W per sec)?
4) Number of simultaneous users?
5) Environment (Java/Microsoft)?
6) How do you plan to connect to the database?
ESRI doesn't make a DBMS, they make middleware...
But on databases, you should almost certainly use PostGres (PostGIS).
This is the operation you want: ST_Contains. I think PHP is the easiest language to use for this, but get the query working in PGAdmin, then do it in your server side scripting language. Or whatever!
How do spatial algorithms help?
There are many ways spatially based algorithms can improve upon traditional algorithms. Often, you can use spatial algorithms to drastically lower the amount of records you have to loop through, such as when using distance in your calculation.
Give me an example!
Let's use this question that was asked today as an example. ...