The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

26

If you want to calculate the bounds of a GeoJSON-Layer you can do: var geojsonLayer = L.geoJson(your_data).addTo(map); map.fitBounds(geojsonLayer.getBounds()); Example: http://jsfiddle.net/expedio/qgkbrjwt/ (Map zooms to Layer extent after the Layer is completely loaded). If you want to calculate the Bounds of each single feature you can do the following:...


8

The problem is that you've got the wrong coordinate order. WKT for SRID 4326 is longitude then latitude (think Cartesian, it is X then Y). The error is telling you that -122 is not a valid latitude. The geometry (or geography) needs to look like: SELECT ST_GeographyFromText('SRID=4326;POINT(-122 37)')... SELECT ST_GeographyFromText('SRID=4326;POINT(2 48)')...


6

You can use shapely to access the underlying GEOS API and create the polygons: from shapely import wkt from shapely.ops import linemerge, unary_union, polygonize POLY = "POLYGON ((34.67491149902344 31.59900710035676, 34.85000610351562 31.59900710035676, 34.85000610351562 31.73867905688433, 34.67491149902344 31.73867905688433, 34.67491149902344 31....


5

Finally I managed to solve the issue. The problem came from the following line: var geojsonFeature = ["{{ new_roads_json }}"]; I put the square brackets because without them it raised invalid objects errors. Thus, I thought that it was the right syntax. Finally, I figured out that the real problem was that the system translated the quotation " as &quot....


4

I ended up solving this by overriding the admin model in admin.py, and setting the latitude/longitude fields as read-only like this: class MarkerAdmin(admin.OSMGeoAdmin): default_lon = -93 default_lat = 27 default_zoom = 15 readonly_fields = ('Latitude','Longitude') admin.site.register(Marker, MarkerAdmin) I then modified the relevant ...


4

In general, debugging JavaScript code is not as easy as debugging your python code although firebug has made the problem much simpler already. When it comes to js libraries like OpenLayers, first make sure you have the uncompressed version for development. When some error occurs, you can find the source file and the code line the defect originates in ...


3

The Overpass Turbo query for a list of all countries is [out:csv("name:en")];relation["admin_level"="2"];out; You can get it from the command line with overpass-api.de/api/interpreter?data=%5Bout%3Acsv%28%22name%3Aen%22%29%5D%3Brelation%5B%22admin_level%22%3D%222%22%5D%3Bout%3B%0A


3

Maybe you can achieve this if you use Django 1.9, where you can use the new geographic database functions api. If you buffer the reference point, then annotate the service areas with the distance to the buffer, and finally filter that distance against the radius. I am not sure if annotations can be used with F expressions, but if they do, the following ...


3

You need a Javascript library for that. For example OpenLayers or LeafLeat. I'll show you one way to display data with OL. First you have to create models in models.py: # Creates point layer in database class ShapefilePoint(models.Model): id = models.IntegerField(primary_key=True) name = models.CharField(max_length=25) geom = models.PointField() ...


3

If your data to filter is not too complex, use the OGDL/GDAL filtering to reduce your original shapefile before loading anything (QGIS can do the same if you prefer GUI) ogr2ogr yoursubsetshp.shp youroriginalshp.shp -sql 'SELECT * FROM youroriginalshp WHERE YOUR_COLUMN=VALUE' You can find some SQL query for OGR/GDAL at the official doc http://www.gdal.org/...


3

All javascript libraries come in source form, so it is only a matter of taking the time to dive into the code. OpenLayers is no different, only you are probably using the minified, compressed into a single huge file version which is hard to read for humans. To help with debugging you should use the non-minified version of the libraries when developing and ...


2

I'm not sure your GeoJSON is correct. 1) I don't think you want to use parenthesis, 2) your geometry coordinates should be [longitude, latitude] (you have it reversed). GeoJSONlint.com is a great resource for validating the syntax. Like this: { "type": "Feature", "geometry": { "type": "Point", "coordinates": [-105,35] }, "...


2

admin.site.register(Poly, admin.GeoModelAdmin) or admin.site.register(Poly, admin.OSMGeoAdmin) # for openstreet map


2

I'm using both, each for its own purpose. I believe that most simple filtering queries you can make on PostGis have an equivalent on MongoDB (within, near, intersection). MongoDB has the additional advantage of being capable to ingest a sparse schema and nested properties (sure, pg can do this too, but you need to k ow beforehand which properties you will ...


2

Use geojson-bbox to calculate the bbox of any geojson Usage: <script src="path/to/geojson-bbox.min.js"></script> var extent = bbox(geojson); //extent is an array [left, bottom, right, top] There is npm module for geojson-bbox


2

The offender may well be this line: poly = center.buffer(2000) Are you certain those units are in meters? I've had issues with rasters being created at 0.5 arc degrees as apposed to 0.5m. EDIT: Try: poly = center.buffer(0.018) if the result is around 2000m my final answer would be that arc degrees is the unit of measure.


2

In this case the best is use annotations. If your model looks similar to: class Country(gismodels.Model): name = models.TextField() geom = gismodels.PolygonField(srid=4326, geography=True) Then when you get your models you can use Area function to get it annotated to your model like that: from django.contrib.gis.db.models.functions import Area ......


2

Basically you want to put a div there, then using HTML create a table, Then with the layer.on('click') event populate the layer with the feature attributes. <div class="sidebar"> <h3 style="text-align:center;">Bird Map</h3> <table> <tr> <th align="left">Common Name</th> <td id='f1'>&...


2

You've put yourself into a bad state by simply removing the Python directory like that. Your best chance to get everything working as you want will involve tearing it all down and building it back up. NOT trying to fix what you've done. I'd: remove Python 3.x remove ArcMap Then, in this order: Install ArcMap Install Python 3.x pip install Django ...


2

You did not initialize your WeatherStationForm within the view. To do so, you have to inherit from TemplateView and override get_context function: Example (not tested): # Normally in views.py class MapView(TemplateView): template_name = 'index.html' def get_context(self, **kwargs): context = {'weatherstation': WeatherStationForm()} ...


2

(Wrote a comment about this and the OP said it was right, so I will put it here for other people to read as a answer) About the point that causes the different result: is it clearly inside the polygon? Is it right on the border of the polygon? I have had this issue sometimes with points that are right on the border of the polygon. For some reason, when ...


2

Finally working: 'patterns' is not defined in geonode/urls.py. add from django.conf.urls import patterns, url in the imports.


1

a research on the topic of WKT-Geometries and the syntax of st_geogfromtext reveals, that your query should look something like this: select st_distance(st_geogfromtext('srid=4326;multipolygon (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))'),st_geogfromtext('srid=4326;point(40 20)')); st_distance ----------------- 892746.97610591 ...


1

Here's an outline of how I suggest approaching this project. Start by asking some questions. You can ask and answer them yourself, or poll your colleagues and potential users of the site. Who will use this website? What are their needs? Will they use the website to... Make measurements? If so, what kind of measurements? View the data with a variety of ...


1

In your code example you create your own raster model. That is not compatible with the functionality of the django-raster package. The goal of django-raster is to avoid having to create and manage raster models. To use it, first make sure django-raster is correctly installed, see https://django-raster.readthedocs.io/en/stable/installation.html). Then the ...


1

These steps will fix windows installations: Start by upgrading to latest python (3.6), Django (2.x), postgres (10.x) and postgis (2.4.x). Run python to check if your python is 32 or 64 bit (It will be displayed on the screen). Install corresponding OSGeo4W (32 or 64 bit) into C:\OSGeo4W or C:\OSGeo4W64: Note: Select Express Web-GIS Install and click next. ...


1

I'm still using OL2, because it seems to me that OL3 doesn't add any functionality that justifies the enormous coding effort in rewriting existing pages to use it, and moreover, I can't get any of the more recent OL3 releases to work with Firebug or the developer tools in the latest version of FF. Nevertheless, I do have a working OL3 example here ... http:/...


1

You can do it if they have a relation to each other. First add a foreignkey Field to the child model. That will point to the parent model. To update the linestring you can select the related child data, directly from the parent, making use of the related set, created automatically by Django. Example: class ParentModel(): name = models.CharField() ...


1

GeoDjango is based on the GEOS library as Shapely. If you don't use Django it is more interesting to work with this module (many examples in GIS SE) Following the explanations of GEOS: Prepared Geometries, a Prepared Geometry is a spatial predicate (only True or False). Geometries are "prepared" ala SQL for efficient batch operations (Efficient batch ...


1

The Tech Crunch article CartoDB’s Odyssey.js Is An Open-Source Tool For Telling Stories With Interactive Maps points at Daring Fireball as the type of markdown. There is an associated discussion list on the Daring Fireball site so perhaps it would be the resource from which to get a definitive answer.


Only top voted, non community-wiki answers of a minimum length are eligible