You will need to change the subject line to get help on a new topic my friend. Jody
On 12/08/2009, at 7:14 PM, iceDice wrote: > > Thanks Jody, > > These days i tried to play with GeoTools graph module and > DijkstraShortestPathFinder in > order to find the best route between two points on map. > I used BasicLineGraphGenerator to create graph from line segments > which are > created from > features. I also used DijkstraShortestPathFinder(graph, source, > weighter) to > find the best path > between source and destination node. I also succeed to create > shapefile > (with your help :)) > which represents best path and display route on the map. > > Now i am trying to create graph which will take into consideration > one way > streets, but i can't see > any way how to specify one way streets to Dijkstra algorithm. I > searched > forum and find out that i > should use DijkstraShortestPathFinder(graph.getGraph(),Iterator) and > define > iterator as > DirectedDijkstraIterator. However i have no idea how to do that, and > i don't > see how i > can specify that some line segment(s) are one-way and others are > not, and > which way is banned. > I tried to find something about this issue in user guide but there is > nothing about it. > > I will be very grateful if someone can help me, > > Best regards. > > > > Jody Garnett-2 wrote: >> >> The second tutorials has this covered: >> - http://docs.codehaus.org/display/GEOTDOC/06+CSV2SHP+Lab >> >> Either: >> - final SimpleFeatureType TYPE = DataUtilities.createType("Location", >> "location:Point,name:String"); >> - or use a FeatureTypeBuilder >> >> SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); >> builder.setName( "Location" ); >> builder.setCRS( DefaultGeographicCRS.WGS84 ); >> >> //add attributes in order >> builder.add( "Location", Point.class ); >> builder.length(15).add( "Name", String.class ); >> >> //build the type >> final SimpleFeatureType LOCATION = builder.buildFeatureType(); >> return LOCATION; >> >> Jody >> On 07/08/2009, at 9:09 PM, iceDice wrote: >> >>> >>> Hello, >>> >>> I have array of com.vividsolutions.jts.geom.LineSegment objects and >>> i want >>> to create new shapefile from it >>> to display it on map. >>> >>> I follow lab on http://docs.codehaus.org/display/GEOTDOC/07+FeatureStore >>> but >>> when i try to do following: >>> >>> FeatureCollection<SimpleFeatureType, SimpleFeature> collection = >>> FeatureCollections.newCollection(); >>> org.opengis.feature.simple.SimpleFeatureType featureType; >>> MultiLineString line; >>> ... >>> collection.add(featureType.create(new Object[] { line })); >>> >>> i found out that org.opengis.feature.simple.SimpleFeatureType don't >>> have >>> method create at all. >>> I try to cast it to org.geotools.feature.SimpleFeatureType but got >>> exception: >>> java.lang.ClassCastException: >>> org.geotools.feature.simple.SimpleFeatureTypeImpl cannot be cast to >>> org.geotools.feature.SimpleFeatureType >>> >>> I hope so someone can help me about this. >>> >>> Here is my complete code: >>> public static void writeToShapefile(LineSegment[] lineSegments) { >>> DefaultTransaction transaction = new >>> DefaultTransaction("Example1"); >>> try { >>> FileDataStoreFactorySpi factory = new >>> IndexedShapefileDataStoreFactory(); >>> File file = new File("myShp.shp"); >>> >>> //Map map = Collections.singletonMap("shapefile url", >>> file.toURI().toURL()); >>> Map map = Collections.singletonMap("url", >>> file.toURI().toURL()); >>> ShapefileDataStore myDataStore = >>> (ShapefileDataStore)factory.createNewDataStore(map); >>> myDataStore.forceSchemaCRS(CRS.decode("EPSG:4326")); >>> SimpleFeatureType featureType = >>> DataUtilities.createType("best_path", >>> "geom:MultiLineString"); >>> myDataStore.createSchema(featureType); >>> >>> /* populate collection from line segments */ >>> FeatureCollection<SimpleFeatureType, SimpleFeature> fc = >>> populate(featureType, lineSegments); >>> >>> /* write features to shape file */ >>> FeatureSource<SimpleFeatureType, SimpleFeature> source = >>> myDataStore.getFeatureSource("best_path"); >>> if (source instanceof FeatureStore) { >>> // you have write access >>> FeatureStore<SimpleFeatureType, SimpleFeature> store = >>> (FeatureStore<SimpleFeatureType, SimpleFeature>) source; >>> store.setTransaction(transaction); >>> try { >>> store.addFeatures(fc); >>> transaction.commit(); >>> transaction.close(); >>> } catch (Exception eek) { >>> try { >>> transaction.rollback(); >>> } catch (IOException e) { >>> e.printStackTrace(); >>> } >>> } >>> } else { >>> // read-only >>> } >>> } catch (Exception e) { >>> // TODO Auto-generated catch block >>> e.printStackTrace(); >>> } >>> } >>> >>> public static FeatureCollection<SimpleFeatureType, SimpleFeature> >>> populate(SimpleFeatureType featureType, LineSegment[] >>> lineSegments) { >>> FeatureCollection<SimpleFeatureType, SimpleFeature> collection = >>> FeatureCollections.newCollection(); >>> try { >>> GeometryFactory gf = new GeometryFactory(); >>> for (int i = 0; i < lineSegments.length; i++) { >>> LineString[] lsTemp = new LineString[1]; >>> Coordinate c0 = lineSegments[i].p0; >>> Coordinate c1 = lineSegments[i].p1; >>> Coordinate[] coords = new Coordinate[2]; >>> coords[0] = c0; >>> coords[1] = c1; >>> LineString ls = gf.createLineString(coords); >>> lsTemp[0] = ls; >>> MultiLineString line = gf.createMultiLineString(lsTemp); >>> collection.add(featureType.create(new Object[] { line >>> })); >>> } >>> return collection; >>> } catch (Exception iae) { >>> iae.printStackTrace(); >>> return null; >>> } >>> } >>> >>> -- >>> View this message in context: >>> http://n2.nabble.com/WriteToShapefile-tp3403703p3403703.html >>> Sent from the geotools-gt2-users mailing list archive at Nabble.com. >>> >>> ------------------------------------------------------------------------------ >>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 >>> 30-Day >>> trial. Simplify your report design, integration and deployment - and >>> focus on >>> what you do best, core application coding. Discover what's new with >>> Crystal Reports now. http://p.sf.net/sfu/bobj-july >>> _______________________________________________ >>> Geotools-gt2-users mailing list >>> [email protected] >>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> >> >> ------------------------------------------------------------------------------ >> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 >> 30-Day >> trial. Simplify your report design, integration and deployment - >> and focus >> on >> what you do best, core application coding. Discover what's new with >> Crystal Reports now. http://p.sf.net/sfu/bobj-july >> _______________________________________________ >> Geotools-gt2-users mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> >> > > -- > View this message in context: > http://n2.nabble.com/WriteToShapefile-tp3403703p3429552.html > Sent from the geotools-gt2-users mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 > 30-Day > trial. Simplify your report design, integration and deployment - and > focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Geotools-gt2-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
