[SERVER-11988] Cant create 2dsphere index on array of GeoJSON LineString: ""Can't extract geo keys from object, malformed geometry?" Created: 06/Dec/13  Updated: 10/Dec/14  Resolved: 26/Jun/14

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: 2.5.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Fabian Köster Assignee: Unassigned
Resolution: Done Votes: 0
Labels: indexing
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Gentoo Linux amd64


Operating System: Linux
Steps To Reproduce:

1.) insert document mentioned previously
2.) Try to create 2dsphere index on field 'segments'

Participants:

 Description   

I have a database containing way segments from OpenStreetMap stored as an array of GeoJSON LineString objects:

> db.ways.findOne({}, { segments: true})
{
	"segments" : [
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2228032,
					50.8051785
				],
				[
					7.2226525,
					50.8054414
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2226525,
					50.8054414
				],
				[
					7.2224028,
					50.805692
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2224028,
					50.805692
				],
				[
					7.2217995,
					50.8062804
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2217995,
					50.8062804
				],
				[
					7.2215501,
					50.8065347
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2215501,
					50.8065347
				],
				[
					7.2210556,
					50.8070833
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2210556,
					50.8070833
				],
				[
					7.2208635,
					50.8074685
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2208635,
					50.8074685
				],
				[
					7.2200495,
					50.8082661
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2200495,
					50.8082661
				],
				[
					7.2200803,
					50.8084219
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2200803,
					50.8084219
				],
				[
					7.2201153,
					50.808599
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2201153,
					50.808599
				],
				[
					7.2200909,
					50.8087172
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2200909,
					50.8087172
				],
				[
					7.2198782,
					50.8088329
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2198782,
					50.8088329
				],
				[
					7.218674,
					50.8100349
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.218674,
					50.8100349
				],
				[
					7.2179697,
					50.8103464
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2179697,
					50.8103464
				],
				[
					7.2176172,
					50.8104984
				]
			]
		},
		{
			"type" : "LineString",
			"coordinates" : [
				[
					7.2176172,
					50.8104984
				],
				[
					7.2168889,
					50.8111111
				]
			]
		}
	],
	"_id" : ObjectId("52a086fe2308d1ac1e000001")
}

Trying to create a 2dsphere index throws the following error:

> db.ways.ensureIndex({segments : "2dsphere"})
{
	"err" : "Can't extract geo keys from object, malformed geometry?: { tags: { highway: \"service\", service: \"parking_aisle\" }, nodeRefs: [ \"270524743\", \"1633119639\", \"1633119637\", \"1633119640\", \"1633119638\", \"510854\", \"510855\", \"11766986\", \"1744718756\", \"11766983\", \"1744718765\", \"11766978\", \"11766975\", \"510863\", \"510864\", \"510865\" ], id: \"4008272\", nodes: [ { tags: {}, id: \"270524743\", lat: 50.8051785, lon: 7.2228032 }, { tags: {}, id: \"1633119639\", lat: 50.8054414, lon: 7.2226525 }, { tags: {}, id: \"1633119637\", lat: 50.805692, lon: 7.2224028 }, { tags: {}, id: \"1633119640\", lat: 50.8062804, lon: 7.2217995 }, { tags: {}, id: \"1633119638\", lat: 50.8065347, lon: 7.2215501 }, { tags: { created_by: \"JOSM\", ele: \"84.2526855469\", time: \"2004-12-28T16:40:08Z\" }, id: \"510854\", lat: 50.8070833, lon: 7.2210556 }, { tags: { ele: \"84.2526855469\", time: \"2004-12-28T16:40:13Z\" }, id: \"510855\", lat: 50.8074685, lon: 7.2208635 }, { tags: {}, id: \"11766986\", lat: 50.8082661, lon: 7.2200495 }, { tags: {}, id: \"1744718756\", lat: 50.8084219, lon: 7.2200803 }, { tags: {}, id: \"11766983\", lat: 50.808599, lon: 7.2201153 }, { tags: {}, id: \"1744718765\", lat: 50.8087172, lon: 7.2200909 }, { tags: {}, id: \"11766978\", lat: 50.8088329, lon: 7.2198782 }, { tags: {}, id: \"11766975\", lat: 50.8100349, lon: 7.218674 }, { tags: {}, id: \"510863\", lat: 50.8103464, lon: 7.2179697 }, { tags: {}, id: \"510864\", lat: 50.8104984, lon: 7.2176172 }, { tags: {}, id: \"510865\", lat: 50.8111111, lon: 7.2168889 } ], segments: [ { type: \"LineString\", coordinates: [ [ 7.2228032, 50.8051785 ], [ 7.2226525, 50.8054414 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2226525, 50.8054414 ], [ 7.2224028, 50.805692 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2224028, 50.805692 ], [ 7.2217995, 50.8062804 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2217995, 50.8062804 ], [ 7.2215501, 50.8065347 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2215501, 50.8065347 ], [ 7.2210556, 50.8070833 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2210556, 50.8070833 ], [ 7.2208635, 50.8074685 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2208635, 50.8074685 ], [ 7.2200495, 50.8082661 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2200495, 50.8082661 ], [ 7.2200803, 50.8084219 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2200803, 50.8084219 ], [ 7.2201153, 50.808599 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2201153, 50.808599 ], [ 7.2200909, 50.8087172 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2200909, 50.8087172 ], [ 7.2198782, 50.8088329 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2198782, 50.8088329 ], [ 7.218674, 50.8100349 ] ] }, { type: \"LineString\", coordinates: [ [ 7.218674, 50.8100349 ], [ 7.2179697, 50.8103464 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2179697, 50.8103464 ], [ 7.2176172, 50.8104984 ] ] }, { type: \"LineString\", coordinates: [ [ 7.2176172, 50.8104984 ], [ 7.2168889, 50.8111111 ] ] } ], _id: ObjectId('52a086fe2308d1ac1e000001') }",
	"code" : 16755,
	"n" : 0,
	"connectionId" : 2,
	"ok" : 1
}

I checked the format with http://geojsonlint.com/ but everything seems to be correct. Am I missing something or is indexing such an array not supported yet?



 Comments   
Comment by Fabian Köster [ 27/Jun/14 ]

Hi Thomas,

thanks for the hint, I will try that!

Regards,
Fabian

Comment by Thomas Rueckstiess [ 26/Jun/14 ]

Hi Fabian,

I believe the correct GeoJSON Format that you're looking for is a MultiLineString, which we started supporting with MongoDB version 2.6.

Regards,
Thomas

Comment by Fabian Köster [ 23/Dec/13 ]

OK, I found a workaround for my application:

Instead of using way segments (of two points each) I now create GeoJSON LineStrings over the whole path:

> db.ways.findOne()
{
"loc" :

{ "type" : "LineString", "coordinates" : [ [ 7.2228032, 50.8051785 ], [ 7.2226525, 50.8054414 ], [ 7.2224028, 50.805692 ], [ 7.2217995, 50.8062804 ], [ 7.2215501, 50.8065347 ], [ 7.2210556, 50.8070833 ], [ 7.2208635, 50.8074685 ], [ 7.2200495, 50.8082661 ], [ 7.2200803, 50.8084219 ], [ 7.2201153, 50.808599 ], [ 7.2200909, 50.8087172 ], [ 7.2198782, 50.8088329 ], [ 7.218674, 50.8100349 ], [ 7.2179697, 50.8103464 ], [ 7.2176172, 50.8104984 ], [ 7.2168889, 50.8111111 ] ] }

,
"_id" : ObjectId("52b86eb47ed621e97e000001")
}

I can now create a 2dsphere index over the 'loc' attribute as expected:

> db.ways.ensureIndex(

{"loc": "2dsphere"}

);

So the problem seems to be that 2dsphere index does not work over lists of LineStrings.

Generated at Thu Feb 08 03:27:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.