Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does a Feature's id change when its added to a Layer? #37

Closed
timkeane opened this issue Apr 4, 2017 · 1 comment
Closed

Why does a Feature's id change when its added to a Layer? #37

timkeane opened this issue Apr 4, 2017 · 1 comment

Comments

@timkeane
Copy link

timkeane commented Apr 4, 2017

https://github.com/timkeane/geoscript-test/blob/master/src/test/groovy/nyc/FeatureIdTest.groovy

package nyc

import spock.lang.*

import geoscript.feature.*
import geoscript.layer.Layer
import geoscript.geom.*

class ProximityTest extends Specification {

	def 'test that feature ids persist'(){
		given:
			Schema schema = new Schema('mySchema', [['geom', 'Point'], ['name', 'string'], ['address', 'string']])
			def attrs = [geom: new Point(1, 10), name: 'myName', address: 'myAddress']
			Feature inFeature = new Feature(attrs, 'myFID', schema)
			Layer layer = new Layer('myLayer', schema)
			layer.add(inFeature)
		when:
			Feature outFeature = layer.getFeatures()[0]
		then:
			inFeature.getId() == 'myFID' 
			inFeature.getId() == outFeature.getId() 
	}
}
@jericks
Copy link
Member

jericks commented Apr 4, 2017

The Feature ID is controlled by the Workspace (GeoTools DataStore). The way you are creating Layers is actually using a Memory Workspace behind the scenes. It creates ids like 'fid-4a2c8996_15b3b3e6f5b_-7ffc'. If you use a Directory Workspace (which creates Shapefiles) you get an id like 'myLayer.1'.

The GeoTools docs have a good explanation: http://docs.geotools.org/stable/userguide/library/data/featuresource.html (look for Handling of FeatureID).

I hope that helps.

@jericks jericks closed this as completed Apr 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants