Herkes GeoAlchemy ile Flask için herhangi bir örnek kod sağlayabilir mi?GeoAlchemy örnek kodlu örnek kod
cevap
SQLAlchemy 0.8 kullanarak, Flask-SQLAlchemy ve Geoalchemy 2:
from app import db
from geoalchemy2.types import Geometry
class Point(db.Model):
"""represents an x/y coordinate location."""
__tablename__ = 'point'
id = db.Column(db.Integer, primary_key=True)
geom = db.Column(Geometry(geometry_type='POINT', srid=4326))
Örnek sorgu: x ve y koordinatlarının sonucu dönüştürme
from geoalchemy2.elements import WKTElement
from app import models
def get_nearest(lat, lon):
# find the nearest point to the input coordinates
# convert the input coordinates to a WKT point and query for nearest point
pt = WKTElement('POINT({0} {1})'.format(lon, lat), srid=4326)
return models.Point.query.order_by(models.Point.geom.distance_box(pt)).first()
bir yolu (GeoJSON dönüştürmek ve koordinatları ayıkla):
import geoalchemy2.functions as func
import json
from app import db
def point_geom_to_xy(pt):
# extract x and y coordinates from a point geometry
geom_json = json.loads(db.session.scalar(func.ST_AsGeoJSON(pt.geom)))
return geom_json['coordinates']
Flask kullanımıyla sınırlı değilseniz, Pylons'a dayanan ve GeoAlchemy kullanan bir MapFish denemek isteyebilirsiniz.
Flask-SQLAlchemy ile birlikte kullanabilirsiniz, ancak bunu düz SQLAlchemy ile de kullanabilirsiniz. Sadece sample models from GeoAlchemy'u Flask-SQLAlchemy'ye çevir. Bunun gibi bir şey: Bu kodu test etmedim, ancak adil bir transkripsiyon olmalıydı,
Bu kod çalışmıyor: size "AttributeError" verir: 'SQLAlchemy' nesnesinin 'GeometryColumn' özelliği yoktur. – jsalonen
from myapp import db
from geoalchemy import GeometryColumn, Point
class FixXX(db.Model):
__tablename__ = 'fixXX'
fix_pk = db.Column(db.Integer, primary_key=True)
fix = db.Column(db.String)
geometry = GeometryColumn(Point(2, srid=4326))
GeometryDDL(FixXX.__table__)
- 1. C++ Google Stil Kılavuzu'na Örnek Örnek Kod?
- 2. Android SSH Örnek Kod
- 3. Ana Detay Örnek Kod
- 4. Dapper'ın Açıklanması Örnek Kod
- 5. Örnek?
- 6. İşte benim örnek kod, Windows
- 7. Perl Net :: OAuth2 örnek kod
- 8. Örnek kod örneği ve örnek olarak aynı anda işlev
- 9. Örnek
- 10. Örnek
- 11. iPhone Facebook oee ile örnek kod
- 12. CFPropertyListCreateDeepCopy Bu örnek kod çalışır Nedense NSNull
- 13. google android örnek kod demo kullanımı nasıl
- 14. d3.js & json - basit örnek kod?
- 15. ComponentsSeparatedByCharactersInSet için herhangi bir örnek kod? (iPhone'da)
- 16. Delphi 2010/XE2 MDI Örnek - Eksik Kod
- 17. Örnek cordova 5.0.0 için örnek proje aldım
- 18. Örnek adından AWS'deki örnek nasıl alınır?
- 19. Sıvı şablonlarında örnek örnek yöntemlerine geçirme değişkenleri
- 20. Ayrılmış örnek için RDS örnek kurtarması
- 21. Örnek dosyaları
- 22. socket.io örnek
- 23. türetilmiş örnek
- 24. Örnek Uygulama?
- 25. Komple örnek
- 26. Örnek üye,
- 27. Örnek arıyor MediaFileUpload kullanarak
- 28. Örnek yöntemlere nasıl başvurulur?
- 29. C# Örnek Başlangıç
- 30. Python durumlar (Belgeleri Örnek)
Özellikle ne yapmak için? –