Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* This program is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
package org.opentripplanner.graph_builder.module.shapefile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.geotools.data.FeatureSource;
import org.geotools.data.Query;
import org.geotools.factory.Hints;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.ReferencingFactoryFinder;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.referencing.crs.CRSAuthorityFactory;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opentripplanner.common.geometry.GeometryUtils;
import org.opentripplanner.common.model.P2;
import org.opentripplanner.graph_builder.services.DefaultStreetEdgeFactory;
import org.opentripplanner.graph_builder.services.GraphBuilderModule;
import org.opentripplanner.graph_builder.services.StreetEdgeFactory;
import org.opentripplanner.graph_builder.services.shapefile.FeatureSourceFactory;
import org.opentripplanner.graph_builder.services.shapefile.SimpleFeatureConverter;
import org.opentripplanner.routing.alertpatch.Alert;
import org.opentripplanner.routing.edgetype.StreetEdge;
import org.opentripplanner.routing.edgetype.StreetTraversalPermission;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.services.notes.StreetNotesService;
import org.opentripplanner.routing.vertextype.IntersectionVertex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.MultiLineString;
import org.opentripplanner.util.NonLocalizedString;
/**
* Loads a shapefile into an edge-based graph.
*
*/
public class ShapefileStreetModule implements GraphBuilderModule {
private static Logger log = LoggerFactory.getLogger(ShapefileStreetModule.class);
private FeatureSourceFactory _featureSourceFactory;
private ShapefileStreetSchema _schema;
public StreetEdgeFactory edgeFactory = new DefaultStreetEdgeFactory();
public List provides() {
return Arrays.asList("streets");
}
public List getPrerequisites() {
return Collections.emptyList();
}
public void setFeatureSourceFactory(FeatureSourceFactory factory) {
_featureSourceFactory = factory;
}
public void setSchema(ShapefileStreetSchema schema) {
_schema = schema;
}
@Override
public void buildGraph(Graph graph, HashMap, Object> extra) {
try {
FeatureSource featureSource = _featureSourceFactory
.getFeatureSource();
CoordinateReferenceSystem sourceCRS = featureSource.getInfo().getCRS();
Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG",
hints);
CoordinateReferenceSystem worldCRS = factory
.createCoordinateReferenceSystem("EPSG:4326");
Query query = new Query();
query.setCoordinateSystem(sourceCRS);
query.setCoordinateSystemReproject(worldCRS);
FeatureCollection features = featureSource
.getFeatures(query);
features = featureSource.getFeatures(query);
HashMap> intersectionNameToId = new HashMap>();
SimpleFeatureConverter streetIdConverter = _schema.getIdConverter();
SimpleFeatureConverter streetNameConverter = _schema.getNameConverter();
SimpleFeatureConverter> permissionConverter = _schema
.getPermissionConverter();
SimpleFeatureConverter noteConverter = _schema.getNoteConverter();
HashMap intersectionsByLocation =
new HashMap();
SimpleFeatureConverter> safetyConverter = _schema.getBicycleSafetyConverter();
SimpleFeatureConverter slopeOverrideCoverter = _schema.getSlopeOverrideConverter();
SimpleFeatureConverter featureSelector = _schema.getFeatureSelector();
// Keep track of features that are duplicated so we don't have duplicate streets
Set