私はDjangoをかなり新しくしており、1週間以上これに固執しています。私はどのようにコード化し、データをマッピングして個人的なサイトを作ろうとしているのか自分自身を教えています。私はkml/xml文字列にフォーマットされ、テキストボックスに格納されているhtmlのjavascriptマップから取得したデータを使用しようとしています。KMLをPostgisに変換する-Django/Python
マッピングリソース(geodjango、postgis)を使用してkml文字列を取得し、データベースに配置する際に問題があります。ドキュメンテーションは非常に限られているように見え、インターネット上では高低検索されています。ここで
は、私が持っているもののブレークダウンです:
HTML:
(マップ)
<input name="mapdata" type="button" value="Generate KML" onclick="convert_to_kml"/>
<textarea id="kmlString" style="blahblah"></textarea>
テキストエリアにKML文字列を配置する
ボタンモデル:
class JobMap(models.Model):
name = models.CharField(max_length=200)
description = models.CharField(max_length=200)
mpoly = models.GeometryCollectionField(srid=4326)
objects = models.GeoManager()
def __str__(self):
return self.name`
再生回数:
def map_import(request):
if request.method == 'POST':
map_data = request.POST.get('kmlString')
#Create a temp file of the string (I think it needs to be a temp file in order for ogr2ogr can read it)
f = request.FILES[map_data]
temp = tempfile.NamedTemporaryFile(delete=False)
temp.write(f.read())
temp.close()
JobMap.objects.raw('''ogr2ogr - f "PostgreSQL"
PG:"host=localhost user=user dbname=database password=password"
temp.name''')
を私はそのようなスタイル、名前や説明など、すべてのKMLデータを保存しようとするとpostgis-にKMLデータのすべてを変換したいです。
GDALではクエリを実行するためにogr2ogrを提供していますが、これを処理するビューに適切に実装する方法を理解できません。これは正しい方向ですか?私はlibkml(postgisにkmlを処理する)という名前のGDALドライバについて聞いたことがありますが、これを正しく使う方法はまだ分かりません。
または 私はこれをすべて間違っていますか? Postgisの入力と出力でスタイルを保持する方法はありませんか?
これは私が達成しようとしていることについてはっきりしていると思います。
私は何か助けを賞賛する!あなたの貴重な時間がかかり過ぎると、私はあなたのために資金を提供することができます。これは私の絶望を示しています。ハハ!ここで
テキストボックスに例のkml文字列(私がテストして動作しますしている)である:
<?xml version="1.0" encoding="UTF-8" ?> <kml >xmlns="http://www.opengis.net/kml/2.2"> <Document> <Style id="117025122580"> <PolyStyle> <color>4c262ED3</color> </PolyStyle> <LineStyle> <color>4c262ED3</color> <width><![CDATA[3]]></width> </LineStyle> </Style> <Placemark> <name><![CDATA[]]></name> <description><![CDATA[]]></description> <styleUrl>#117025122580</styleUrl> <Polygon> <outerBoundaryIs> <LinearRing> <coordinates> -113.54164123535156,53.58616198075974,0 -113.40980529785156,53.57678609766098,0 -113.42559814453125,53.50823829699392,0 -113.58283996582031,53.53436483388852,0 -113.59451293945312,53.5559886770827,0 </coordinates> </LinearRing> </outerBoundaryIs> </Polygon> </Placemark> <Style id="117025122581"> <PolyStyle> <color>4c262ED3</color> </PolyStyle> <LineStyle> <color>4c262ED3</color> <width><![CDATA[3]]></width> </LineStyle> </Style> <Placemark> <name><![CDATA[]]></name> <description><![CDATA[]]></description> <styleUrl>#117025122581</styleUrl> <Polygon> <outerBoundaryIs> <LinearRing> <coordinates> -113.642578125,53.47678344938643,0 -113.55400085449219,53.47678344938643,0 -113.55400085449219,53.5282428724319,0 -113.642578125,53.5282428724319,0 </coordinates> </LinearRing> </outerBoundaryIs> </Polygon> </Placemark> <Style id="117025122582"> <IconStyle> <scale>1</scale> </IconStyle> </Style> <Placemark> <name><![CDATA[]]></name> <description><![CDATA[]]></description> <styleUrl>#117025122582</styleUrl> <Point> <coordinates>-113.47984313964844,53.61264779961176,0</coordinates> </Point> </Placemark> </Document> </kml>
ありがとうございました!私は数日後にそれを打ち、あなたに戻ってきます! – asdfasdf590