Comments (8)
This is the code I used:
views.py
class MyModelLayer(GeoJSONLayerView):
def get_queryset(self):
context = MyModel.objects.all().filter(...some_filter_here...)
return context
urls.py
url(r'^data/mymodel.geojson$',
MyModelLayer.as_view(model=MyModel,
properties=(
['field1', 'field2',]
)),
name='mymodel-geojson'),
from django-geojson.
Hi !
It looks like you're confused between the view (serving GeoJSON) and the template filter (embedding GeoJSON within an HTML template).
So, if you need to serve GeoJSON with some properties, just add this in urls.py
:
GeoJSONLayerView.as_view(model=MyModel, properties=('field1', 'field2'), name='myname')
But if you need to embed some GeoJSON within an HTML page (less common to be honest), you may be right, the many parameters are maybe useless ! I will open another issue for that :)
from django-geojson.
I ended up using an inherited generic views, redefining the get_queryset method to return the desired queryset.
Though, still curious about how to pass the parameters to the geojsonfeature filter.
from django-geojson.
Hi, no I am not confused :) I exactly did what you suggested in urls.
I had then to use the generic view approach and redefine the get_queryset as I did not find a different way to pass a filtered query set.
My question here is: how to pass the parameters to the geojsonfeature filter? Thanks in advance.
from django-geojson.
Ok, great, indeed a filtered queryset like this should work.
Regarding the other question: so far it looks like the template filter geojsonfeature
does not allow parameters (see issue #16). Why do you need it for ?
from django-geojson.
because according to this:
https://github.com/makinacorpus/django-geojson/blob/master/djgeojson/templatetags/geojson_tags.py#L17
we may pass the following parameters to the filter:
def geojsonfeature(source, geometry_field='geom', properties=None, srid=GEOJSON_DEFAULT_SRID)
but cannot figure out how to pass the properties and srid parameters (it looks like a Django filter will accept just one parameter from template).
The only way I can figure out to use this filter if you need to modify its parameters is by inheriting from it and change the parameters in the inherited filter.
Is this the intended behaviour?
Regards
from django-geojson.
Yes indeed, this part of the code was written in a way that cannot be used :D (purpose of issue #16)
We could specify only one parameter as string (split on :
)
{{ object|geojsonfeature:"name,age" }}
{{ object|geojsonfeature:"name:geom" }}
{{ object|geojsonfeature:"title,description:geom:2154" }}
{{ object|geojsonfeature:":geom:4326" }}
from django-geojson.
+1, thanks :)
from django-geojson.
Related Issues (20)
- UWSGI crashes after installing django-geojson HOT 2
- 'Shop' object has no attribute 'geom'
- JSONFormField is removed from jsonfield HOT 1
- Leaflet widget is not rendered automatically for forms.Forms HOT 4
- Generate FeatureCollection GeoJSON from queryset in the database
- Daes it make sense to improve validators process? HOT 2
- jsonfield dependency still required? HOT 1
- Error creating geometry from value 'null' (String input unrecognized as WKT EWKT, and HEXEWKB.) HOT 2
- Make 'name' the default for 'crs_type' HOT 3
- Leaflet warning when using own widget HOT 1
- Migration breakage when switching from 'jsonfield' to django.db.models.JSONField
- OSError exception HOT 2
- Support Request: Trying to map PointFields with no success HOT 2
- GeoJSONLayerView and LoginRequiredMixin HOT 5
- Django 2.0: AttributeError: 'CharField' object has no attribute 'rel' HOT 3
- How I Can Add Circle Support In Geometry Type HOT 1
- Support Model methods with no parameters HOT 1
- Serving geoJson with custom coordinates HOT 1
- Makemigrations Failing - Could not find GDAL. HOT 1
- Object has no attribute 'geom' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-geojson.