[udig-devel] Problem with writing layer with LineString to shapefile

Ingmar Eveslage eveslage at gmail.com
Fri Mar 28 15:25:08 PDT 2008


Thanks for your hint:

MultiLineString works.

I will take care of what createShema() realy creates. Thanks for the  
hint.

Do you know why FeatureCollection collection.toArray() always return  
"null"?
how can a get a Vector or List out of a FeatureCollection?

Thanks

Ingmar

Am 28.03.2008 um 22:34 schrieb Jody Garnett:
> Good Afternoon,
>> I have a map with two layers. the first with a point geometry and  
>> one with a line string geometry using the following featuretype:
>>                CoordinateReferenceSystem crs =  
>> DefaultGeographicCRS.WGS84;
>>                AttributeType line =  
>> AttributeTypeFactory.newAttributeType("GEOMETRY",  
>> LineString.class,true, null,null,crs );
>>                AttributeType stationId1 =  
>> AttributeTypeFactory.newAttributeType("StationID1", String.class,  
>> false, null, "Station1", null);
>>                AttributeType stationId2 =  
>> AttributeTypeFactory.newAttributeType("StationID2", String.class,  
>> false, null, "Station2", null);                   AttributeType  
>> linkQuality = AttributeTypeFactory.newAttributeType("LinkQuality",  
>> Double.class, false, null, 1.0, null);                    
>> linkFeatureType = FeatureTypeBuilder.newFeatureType(new  
>> AttributeType[] { line }, "LinkFeatureType");
> A quick suggestion is to try MultiLineString :-)
>> After editing the layers using the creation tool from udig a want  
>> to save the features on the disk in a shapefile using this method:
>>            Transaction t = new DefaultTransaction();
>>            try {
>>                FeatureCollection collection =  
>> source.getFeatures(); // grab all features
>>                featureStore.addFeatures( collection );
>>                t.commit(); // write it out
>>            }
> You should check that your source features actually match exactly  
> what you expect to write out; even though you created the shapefile  
> as described above you may find that:
> - the feature type is actually your 'filename' rather than  
> "LinkFeatureType" (this may not matter)
> - LineString may be MultiLineString
> - Strings may be assigned a max length
> - please just stop in a debugger and check what you got;  
> createSchema is only a suggestion - a datastore will get as close as  
> it can
>
>> all works fine with the stationFeatureType. I get a shapefile with  
>> all the features. But if i do the same with the linkFeatureType i  
>> get this exception:
>> java.lang.NullPointerException
>>    at org.geotools.data.shapefile.indexed.IndexedShapefileDataStore 
>> $Writer.write(IndexedShapefileDataStore.java:1752)
>>    at org.geotools.data.shapefile.indexed.IndexedShapefileDataStore 
>> $Writer.close(IndexedShapefileDataStore.java:1557)
> So what is happening on this line *exactly*? Is there a chance one  
> of your attributes is *null* when it is not allowed to be by the  
> shapefile format? As an example I am not sure Double is allowed to  
> be null.
>
> Checking the line for you:
>> int dims = JTSUtilities.guessCoorinateDims(g.getCoordinates());
> So there we have it your geometry is null
>> Can anyone tell me whats the problem? i dont know why this does not  
>> work with the LineString class.
>>
>> Thanks for your help.
>>
>> Greats Ingmar
>> _______________________________________________
>> User-friendly Desktop Internet GIS (uDig)
>> http://udig.refractions.net
>> http://lists.refractions.net/mailman/listinfo/udig-devel
>
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel



More information about the udig-devel mailing list