Last active
September 6, 2018 09:08
-
-
Save helllth/efdc007b04c9a172c638 to your computer and use it in GitHub Desktop.
MongoDB Geospatial Queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongoimport --db test --collection auszug --file WuppertalCSV-Auszug1.txt | |
mongoimport --db test --collection auszug --file WuppertalCSV-Auszug2.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.auszug.find().pretty(); | |
//liefert: | |
{ | |
"_id" : ObjectId("55cc78d64b54f13fbdc83a5f"), | |
"_class" : "java.util.LinkedHashMap", | |
"country" : "DE", | |
"country_ci" : "de", | |
"federalstate" : "Nordrhein-Westfalen", | |
"federalstate_ci" : "nordrhein-westfalen", | |
"shortname" : "NW", | |
"shortname_ci" : "nw", | |
"place" : "Wuppertal", | |
"place_ci" : "wuppertal", | |
"postalCode" : "", | |
"postalCode_ci" : "", | |
"street" : "In der Hardt", | |
"street_ci" : "in der hardt", | |
"strassenschluessel" : "01636", | |
"strassenschluessel_ci" : "01636", | |
"houseNumber" : "", | |
"houseNumber_ci" : "", | |
"gemarkungsname" : "Beyenburg", | |
"gemarkungsname_ci" : "beyenburg", | |
"gemarkungsnummer" : "3485", | |
"gemarkungsnummer_ci" : "3485", | |
"flurnummer" : "18", | |
"flurnummer_ci" : "18", | |
"flurstuecksnummer" : "71", | |
"flurstuecksnummer_ci" : "71", | |
"flurstueckskennzeichen" : "3485-18-71", | |
"flurstueckskennzeichen_ci" : "3485-18-71", | |
"nord-sued-ausdehnung" : "41.9", | |
"nord-sued-ausdehnung_ci" : "41.9", | |
"ost-west-ausdehnung" : "39.7", | |
"ost-west-ausdehnung_ci" : "39.7", | |
"geometrie" : "[[[51.2181885715613,7.29310116592042],[51.2180711077149,7.29315500000795],[51.2180146043402,7.29318087509323],[51.2180510867808,7.2931110628814],[51.2180867821676,7.29304278324833],[51.2180788234358,7.29287698257742],[51.2180785254433,7.29287135161007],[51.2180649502488,7.29261094758854],[51.2181466896952,7.29264127400385],[51.2183444480863,7.29267468262702],[51.2183553950257,7.29274140910819],[51.2183882626813,7.29294899111913],[51.2183387941217,7.293032344066],[51.2181885715613,7.29310116592042]]]", | |
"geometrie_ci" : "[[[51.2181885715613,7.29310116592042],[51.2180711077149,7.29315500000795],[51.2180146043402,7.29318087509323],[51.2180510867808,7.2931110628814],[51.2180867821676,7.29304278324833],[51.2180788234358,7.29287698257742],[51.2180785254433,7.29287135161007],[51.2180649502488,7.29261094758854],[51.2181466896952,7.29264127400385],[51.2183444480863,7.29267468262702],[51.2183553950257,7.29274140910819],[51.2183882626813,7.29294899111913],[51.2183387941217,7.293032344066],[51.2181885715613,7.29310116592042]]]" | |
} | |
{ | |
"_id" : ObjectId("55cc78d84b54f13fbdc83eab"), | |
"_class" : "java.util.LinkedHashMap", | |
"country" : "DE", | |
"country_ci" : "de", | |
"federalstate" : "Nordrhein-Westfalen", | |
"federalstate_ci" : "nordrhein-westfalen", | |
"shortname" : "NW", | |
"shortname_ci" : "nw", | |
"place" : "Wuppertal", | |
"place_ci" : "wuppertal", | |
"postalCode" : "42285", | |
"postalCode_ci" : "42285", | |
"street" : "Pauluskirchstraße", | |
"street_ci" : "pauluskirchstraße", | |
"strassenschluessel" : "02617", | |
"strassenschluessel_ci" : "02617", | |
"houseNumber" : "8", | |
"houseNumber_ci" : "8", | |
"gemarkungsname" : "Barmen", | |
"gemarkungsname_ci" : "barmen", | |
"gemarkungsnummer" : "3001", | |
"gemarkungsnummer_ci" : "3001", | |
"flurnummer" : "373", | |
"flurnummer_ci" : "373", | |
"flurstuecksnummer" : "16", | |
"flurstuecksnummer_ci" : "16", | |
"flurstueckskennzeichen" : "3001-373-16", | |
"flurstueckskennzeichen_ci" : "3001-373-16", | |
"nord-sued-ausdehnung" : "85.4", | |
"nord-sued-ausdehnung_ci" : "85.4", | |
"ost-west-ausdehnung" : "88.6", | |
"ost-west-ausdehnung_ci" : "88.6", | |
"geometrie" : "[[[51.2604868579928,7.1664429956711],[51.2605653328786,7.16630760591607],[51.260626713898,7.16641227505004],[51.2606790735522,7.1665329410202],[51.2605656023915,7.16672664040442],[51.2603927960948,7.1670209245405],[51.2603437691445,7.16710440183032],[51.2602712849022,7.16722786977446],[51.2602091781747,7.16733350985025],[51.2600539154088,7.16759789527704],[51.2599251373614,7.16740510695208],[51.2600633160236,7.16716906400015],[51.2600906530734,7.16712242610843],[51.2600986675518,7.1671087488819],[51.260250690214,7.16684943536319],[51.2602639865792,7.16682676169607],[51.2603038050936,7.16675882942231],[51.260363917828,7.1666551023294],[51.2604868579928,7.1664429956711]]]", | |
"geometrie_ci" : "[[[51.2604868579928,7.1664429956711],[51.2605653328786,7.16630760591607],[51.260626713898,7.16641227505004],[51.2606790735522,7.1665329410202],[51.2605656023915,7.16672664040442],[51.2603927960948,7.1670209245405],[51.2603437691445,7.16710440183032],[51.2602712849022,7.16722786977446],[51.2602091781747,7.16733350985025],[51.2600539154088,7.16759789527704],[51.2599251373614,7.16740510695208],[51.2600633160236,7.16716906400015],[51.2600906530734,7.16712242610843],[51.2600986675518,7.1671087488819],[51.260250690214,7.16684943536319],[51.2602639865792,7.16682676169607],[51.2603038050936,7.16675882942231],[51.260363917828,7.1666551023294],[51.2604868579928,7.1664429956711]]]" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.auszug.find().snapshot().forEach(function (fs) { var coords=eval(fs.geometrie); fs.geoJson = { type: "Polygon", coordinates: coords }; db.auszug.save(fs); }); | |
//mit dem Ergebniss: | |
{ | |
"_id" : ObjectId("55cc78d84b54f13fbdc83eab"), | |
"_class" : "java.util.LinkedHashMap", | |
"country" : "DE", | |
"country_ci" : "de", | |
"federalstate" : "Nordrhein-Westfalen", | |
"federalstate_ci" : "nordrhein-westfalen", | |
"shortname" : "NW", | |
"shortname_ci" : "nw", | |
"place" : "Wuppertal", | |
"place_ci" : "wuppertal", | |
"postalCode" : "42285", | |
"postalCode_ci" : "42285", | |
"street" : "Pauluskirchstraße", | |
"street_ci" : "pauluskirchstraße", | |
"strassenschluessel" : "02617", | |
"strassenschluessel_ci" : "02617", | |
"houseNumber" : "8", | |
"houseNumber_ci" : "8", | |
"gemarkungsname" : "Barmen", | |
"gemarkungsname_ci" : "barmen", | |
"gemarkungsnummer" : "3001", | |
"gemarkungsnummer_ci" : "3001", | |
"flurnummer" : "373", | |
"flurnummer_ci" : "373", | |
"flurstuecksnummer" : "16", | |
"flurstuecksnummer_ci" : "16", | |
"flurstueckskennzeichen" : "3001-373-16", | |
"flurstueckskennzeichen_ci" : "3001-373-16", | |
"nord-sued-ausdehnung" : "85.4", | |
"nord-sued-ausdehnung_ci" : "85.4", | |
"ost-west-ausdehnung" : "88.6", | |
"ost-west-ausdehnung_ci" : "88.6", | |
"geometrie" : "[[[51.2604868579928,7.1664429956711],[51.2605653328786,7.16630760591607],[51.260626713898,7.16641227505004],[51.2606790735522,7.1665329410202],[51.2605656023915,7.16672664040442],[51.2603927960948,7.1670209245405],[51.2603437691445,7.16710440183032],[51.2602712849022,7.16722786977446],[51.2602091781747,7.16733350985025],[51.2600539154088,7.16759789527704],[51.2599251373614,7.16740510695208],[51.2600633160236,7.16716906400015],[51.2600906530734,7.16712242610843],[51.2600986675518,7.1671087488819],[51.260250690214,7.16684943536319],[51.2602639865792,7.16682676169607],[51.2603038050936,7.16675882942231],[51.260363917828,7.1666551023294],[51.2604868579928,7.1664429956711]]]", | |
"geometrie_ci" : "[[[51.2604868579928,7.1664429956711],[51.2605653328786,7.16630760591607],[51.260626713898,7.16641227505004],[51.2606790735522,7.1665329410202],[51.2605656023915,7.16672664040442],[51.2603927960948,7.1670209245405],[51.2603437691445,7.16710440183032],[51.2602712849022,7.16722786977446],[51.2602091781747,7.16733350985025],[51.2600539154088,7.16759789527704],[51.2599251373614,7.16740510695208],[51.2600633160236,7.16716906400015],[51.2600906530734,7.16712242610843],[51.2600986675518,7.1671087488819],[51.260250690214,7.16684943536319],[51.2602639865792,7.16682676169607],[51.2603038050936,7.16675882942231],[51.260363917828,7.1666551023294],[51.2604868579928,7.1664429956711]]]", | |
"geoJson" : { | |
"type" : "Polygon", | |
"coordinates" : [ | |
[ | |
[ | |
51.2604868579928, | |
7.1664429956711 | |
], | |
[ | |
51.2605653328786, | |
7.16630760591607 | |
], | |
[ | |
51.260626713898, | |
7.16641227505004 | |
], | |
[ | |
51.2606790735522, | |
7.1665329410202 | |
], | |
[ | |
51.2605656023915, | |
7.16672664040442 | |
], | |
[ | |
51.2603927960948, | |
7.1670209245405 | |
], | |
[ | |
51.2603437691445, | |
7.16710440183032 | |
], | |
[ | |
51.2602712849022, | |
7.16722786977446 | |
], | |
[ | |
51.2602091781747, | |
7.16733350985025 | |
], | |
[ | |
51.2600539154088, | |
7.16759789527704 | |
], | |
[ | |
51.2599251373614, | |
7.16740510695208 | |
], | |
[ | |
51.2600633160236, | |
7.16716906400015 | |
], | |
[ | |
51.2600906530734, | |
7.16712242610843 | |
], | |
[ | |
51.2600986675518, | |
7.1671087488819 | |
], | |
[ | |
51.260250690214, | |
7.16684943536319 | |
], | |
[ | |
51.2602639865792, | |
7.16682676169607 | |
], | |
[ | |
51.2603038050936, | |
7.16675882942231 | |
], | |
[ | |
51.260363917828, | |
7.1666551023294 | |
], | |
[ | |
51.2604868579928, | |
7.1664429956711 | |
] | |
] | |
] | |
} | |
} | |
{ | |
"_id" : ObjectId("55cc78d64b54f13fbdc83a5f"), | |
"_class" : "java.util.LinkedHashMap", | |
"country" : "DE", | |
"country_ci" : "de", | |
"federalstate" : "Nordrhein-Westfalen", | |
"federalstate_ci" : "nordrhein-westfalen", | |
"shortname" : "NW", | |
"shortname_ci" : "nw", | |
"place" : "Wuppertal", | |
"place_ci" : "wuppertal", | |
"postalCode" : "", | |
"postalCode_ci" : "", | |
"street" : "In der Hardt", | |
"street_ci" : "in der hardt", | |
"strassenschluessel" : "01636", | |
"strassenschluessel_ci" : "01636", | |
"houseNumber" : "", | |
"houseNumber_ci" : "", | |
"gemarkungsname" : "Beyenburg", | |
"gemarkungsname_ci" : "beyenburg", | |
"gemarkungsnummer" : "3485", | |
"gemarkungsnummer_ci" : "3485", | |
"flurnummer" : "18", | |
"flurnummer_ci" : "18", | |
"flurstuecksnummer" : "71", | |
"flurstuecksnummer_ci" : "71", | |
"flurstueckskennzeichen" : "3485-18-71", | |
"flurstueckskennzeichen_ci" : "3485-18-71", | |
"nord-sued-ausdehnung" : "41.9", | |
"nord-sued-ausdehnung_ci" : "41.9", | |
"ost-west-ausdehnung" : "39.7", | |
"ost-west-ausdehnung_ci" : "39.7", | |
"geometrie" : "[[[51.2181885715613,7.29310116592042],[51.2180711077149,7.29315500000795],[51.2180146043402,7.29318087509323],[51.2180510867808,7.2931110628814],[51.2180867821676,7.29304278324833],[51.2180788234358,7.29287698257742],[51.2180785254433,7.29287135161007],[51.2180649502488,7.29261094758854],[51.2181466896952,7.29264127400385],[51.2183444480863,7.29267468262702],[51.2183553950257,7.29274140910819],[51.2183882626813,7.29294899111913],[51.2183387941217,7.293032344066],[51.2181885715613,7.29310116592042]]]", | |
"geometrie_ci" : "[[[51.2181885715613,7.29310116592042],[51.2180711077149,7.29315500000795],[51.2180146043402,7.29318087509323],[51.2180510867808,7.2931110628814],[51.2180867821676,7.29304278324833],[51.2180788234358,7.29287698257742],[51.2180785254433,7.29287135161007],[51.2180649502488,7.29261094758854],[51.2181466896952,7.29264127400385],[51.2183444480863,7.29267468262702],[51.2183553950257,7.29274140910819],[51.2183882626813,7.29294899111913],[51.2183387941217,7.293032344066],[51.2181885715613,7.29310116592042]]]", | |
"geoJson" : { | |
"type" : "Polygon", | |
"coordinates" : [ | |
[ | |
[ | |
51.2181885715613, | |
7.29310116592042 | |
], | |
[ | |
51.2180711077149, | |
7.29315500000795 | |
], | |
[ | |
51.2180146043402, | |
7.29318087509323 | |
], | |
[ | |
51.2180510867808, | |
7.2931110628814 | |
], | |
[ | |
51.2180867821676, | |
7.29304278324833 | |
], | |
[ | |
51.2180788234358, | |
7.29287698257742 | |
], | |
[ | |
51.2180785254433, | |
7.29287135161007 | |
], | |
[ | |
51.2180649502488, | |
7.29261094758854 | |
], | |
[ | |
51.2181466896952, | |
7.29264127400385 | |
], | |
[ | |
51.2183444480863, | |
7.29267468262702 | |
], | |
[ | |
51.2183553950257, | |
7.29274140910819 | |
], | |
[ | |
51.2183882626813, | |
7.29294899111913 | |
], | |
[ | |
51.2183387941217, | |
7.293032344066 | |
], | |
[ | |
51.2181885715613, | |
7.29310116592042 | |
] | |
] | |
] | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//laesst man { "flurstueckskennzeichen":1 } weg, bekommt man das ganze objekt | |
db.auszug.find({geoJson:{$geoIntersects: {$geometry: {type: "Point", coordinates: [51.218201,7.292896]}}}},{ "flurstueckskennzeichen":1 }) | |
//mit dem Ergebniss: | |
{ "_id" : ObjectId("55cc78d64b54f13fbdc83a5f"), "flurstueckskennzeichen" : "3485-18-71" } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.auszug.createIndex({geoJson:"2dsphere"}) | |
//Ergebniss | |
{ | |
"createdCollectionAutomatically" : false, | |
"numIndexesBefore" : 1, | |
"numIndexesAfter" : 2, | |
"ok" : 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment