PostGIS performance required with GeoDjango

This is the first time I use GeoDjango with postGIS. After installation and some tests with everything that works fine, I am concerned about query performance when table rows grow.

I keep the geometry of longitude and latitude that I get from Google geocoding (WGS84 or SRID 4326). My problem is that remote operations are very common in my application. I often need to get closer to the spots from the landmark. The geometry of mathematics is very complex, so even if I have a spatial index, there will probably be too much time in the future, having more than 1000 points in a neighboring area.

So, is there a way to project this type of geometry in order to perform remote operations faster? Does anyone know a Django library that can display a Google map containing some of these points?

Any tips on how to speed up spatial queries in GeoDjango?

+6
python django postgis geodjango
source share
3 answers

If you can put your work area into the map projection, it will always be faster, since for things like calculating distance, fewer mathematical mathematical queries are required. However, if you have truly global data, suck it: use geography. If you only have continental US data, use something like EPSG: 2163 http://spatialreference.org/ref/epsg/2163/

The more limited your work area, the more accurate results you can get in a map projection. See Plane State Forecasts for strictly limited, accurate forecasts for US regions. Or UTM forecasts for larger subnational regions.

+3
source share

I am studying this topic. As far as I found, the coordinates you get from the geophysical library are in the SRID 4326 format, so you can store them in a geometry type without any problems. This will be an example of a GeoDjango model using geometry:

class Landmark(models.Model): point = models.PointField(spatial_index = True, srid = 4326, geography = True) objects = models.GeoManager() 

By the way, be very careful to pass longitude / latitude to PointField, in that exact order. geophysics returns latitude / longitude coordinates, so you will need to cancel them.

To convert points in one coordinate system to another, we can use GEOS with GeoDjango. In this example, I will convert the point in 4326 to the famous Google 900913 forecast:

 from django.contrib.gis.geos import Point punto = Point(40,-3) punto.set_srid(900913) punto.transform(4326) punto.wkt Out[5]: 'POINT (0.0003593261136478 -0.0000269494585230)' 

Thus, we can store coordinates in projection systems that will have better math performance. To display points on a Google map in the admin interface. We can use this wonderful article .

I decided to continue working with types of geography, and I will convert them in the future if I need to improve performance.

+2
source share

Typically, GeoDjango will create and use spatial indexes on geometry columns where necessary.

For an application that uses mainly the distance between points, the Geography type (introduced in PostGIS 1.5 and supported by GeoDjango) may be well suited. GeoDjango says that it gives "much better performance in WGS84 remote requests" [link] .

0
source share

All Articles