Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changes into class in order to fix Integer problems.

  • Loading branch information...
commit 6bbaed2d767198eff6e7101419fa85d0b17da43c 1 parent 75b0be9
@moiarcsan moiarcsan authored
View
34 importer/pom.xml
@@ -4,7 +4,41 @@
<groupId>org.gofleet.teleatlas</groupId>
<artifactId>importer</artifactId>
<version>0.0.1-SNAPSHOT</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ <mainClass>org.gofleet.importer.teleatlas.ShapeToOSM</mainClass>
+ <classpathPrefix>dependency/</classpathPrefix>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>true</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
<dependencies>
<dependency>
View
25 importer/src/main/java/org/gofleet/importer/teleatlas/NodeReader.java
@@ -29,13 +29,14 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.nio.charset.Charset;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import org.geotools.data.shapefile.ShpFiles;
import org.geotools.data.shapefile.dbf.DbaseFileReader;
import org.geotools.data.shapefile.dbf.DbaseFileReader.Row;
-import org.geotools.data.shapefile.shp.ShapefileException;
import org.geotools.data.shapefile.shp.ShapefileReader;
import org.geotools.data.shapefile.shp.ShapefileReader.Record;
@@ -45,6 +46,9 @@
public class NodeReader {
+
+ private static int idTemp = 1;
+ private static Map<Long, Integer> idMap = new HashMap<Long, Integer>();
/**
* Method processNodes: write in a temporal file the nodes in
@@ -89,10 +93,12 @@ public static void processNodes(String pathNodes, File tempNodes){
lon = Double.toString(coordinates[i].x);
lat = Double.toString(coordinates[i].y);
// Add to tempNodes file
- writeNodes(fw, id, lat, lon);
+ writeNodes(fw, idTemp, lat, lon, 0);
+ idMap.put(id, idTemp);
}
}
}
+ idTemp++;
}
fw.flush();
} catch (Throwable e) {
@@ -117,7 +123,7 @@ public static void processNodes(String pathNodes, File tempNodes){
* @param lon: String with the longitude of the coordinate from a geometry
*/
public static void writeNodes(FileWriter fw, long ref, String lat,
- String lon) {
+ String lon, int changeset) {
try {
fw.write("<node id=\""
+ ref
@@ -126,10 +132,19 @@ public static void writeNodes(FileWriter fw, long ref, String lat,
+ "\" lon=\""
+ lon
+ "\""
- + " version=\"1\" changeset=\"1\" user=\"teleAtlas2osm\" uid=\"1\" visible=\"true\""
+ + " version=\"1\" changeset=\"" + changeset + "\" user=\"teleAtlas2osm\" uid=\"1\" visible=\"true\""
+ " timestamp=\"2007-01-28T11:40:26Z\"/>\n");
} catch (Throwable e) {
e.printStackTrace();
}
}
+ /**
+ * Method getIDMap: Method to make a hashmap to organize the id values
+ *
+ * return Map<Long, Integer>: return a hashmap where the key is an id from Junction
+ * and its corresponding temporal value in order to have an integer value
+ */
+ public static Map<Long, Integer> getIDMap(){
+ return Collections.synchronizedMap(idMap);
+ }
}
View
331 importer/src/main/java/org/gofleet/importer/teleatlas/RestrictionReader.java
@@ -42,6 +42,8 @@
import org.geotools.data.shapefile.dbf.DbaseFileReader.Row;
public class RestrictionReader {
+ private static Map<Long, Integer> idMap;
+ private static long value = 57240000000000l;
/**
* Method processRestrictions: write in a temporal file the restrictions in
@@ -58,7 +60,9 @@
*
*/
public static void processRestrictions(String pathManeuvers,
- String pathManeuversPath, String pathRestrictions, File file) {
+ String pathManeuversPath, String pathRestrictions, File file,
+ String min) {
+ idMap = NodeReader.getIDMap();
ShpFiles shpFile = null;
boolean useMemoryMapped = false;
Row rdb = null;
@@ -69,8 +73,9 @@ public static void processRestrictions(String pathManeuvers,
// Open file
fw = new FileWriter(file);
shpFile = new ShpFiles(pathManeuvers);
- dbfilereader = new DbaseFileReader(shpFile,
- useMemoryMapped, Charset.defaultCharset());
+ dbfilereader = new DbaseFileReader(shpFile, useMemoryMapped,
+ Charset.defaultCharset());
+ int i = 10;
while (dbfilereader.hasNext()) {
rdb = dbfilereader.readRow();
attributes = getAttributesManeuvers(rdb);
@@ -78,25 +83,49 @@ public static void processRestrictions(String pathManeuvers,
if (attributes.get("FEATTYP").equals("2103")
&& attributes.get("PROMANTYP").equals("0")) {
long id = Long.valueOf(attributes.get("ID"));
- long junctID = Long.valueOf(attributes.get("JNCTID"));
+ // Change the long value by an Integer value
+ id = id - value;
+ long junctIDTemp = Long.valueOf(attributes.get("JNCTID"));
+ Integer junctID = idMap.get(junctIDTemp);
// Get from way and to way from maneuvers path index table
List<String> sequence = getSequence(id, pathManeuversPath);
- String restrictions = getRestriction(id, pathRestrictions);
- if (sequence.size() == 2) {
- long from = Long.valueOf(sequence.get(0));
- long to = Long.valueOf(sequence.get(1));
- String rest = writeRestriction(id, junctID, from, to,
- restrictions);
- fw.write(rest);
- fw.flush();
- } // TODO length > 2
+ for (String restrictions : getRestriction(id,
+ pathRestrictions)) {
+ if (sequence.size() == 2) {
+ long from = Long.valueOf(sequence.get(0));
+ long to = Long.valueOf(sequence.get(1));
+ long minvalue = Long.valueOf(min.toString());
+ long idRes = id - minvalue;
+ String rest = writeRestriction(idRes, junctID,
+ from, to, restrictions);
+ fw.write(rest);
+ fw.flush();
+ i++;
+ } else {
+ // Change node to via
+ long from = Long.valueOf(sequence.get(0));
+ long to = Long
+ .valueOf(sequence.get(sequence.size() - 1));
+ long minvalue = Long.valueOf(min.toString());
+ long idRes = minvalue + i;
+ List<String> memberList = new LinkedList<String>();
+ for (int j = 1; j < sequence.size() - 1; j++) {
+ memberList.add(String.valueOf(sequence.get(j)));
+ }
+ String rest = writeRestrictionVia(idRes,
+ memberList, from, to, restrictions);
+ fw.write(rest);
+ fw.flush();
+ i++;
+ }
+ }
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
- }finally {
+ } finally {
try {
fw.close();
dbfilereader.close();
@@ -110,7 +139,8 @@ public static void processRestrictions(String pathManeuvers,
* Method getAttributesManeuvers: Method to get Maneuvers attributes from a
* Maneuvers shape
*
- * @param rdb: Row with the content of a shapefile Maneuvers line
+ * @param rdb
+ * : Row with the content of a shapefile Maneuvers line
* @return Map<String, String>: Map with attributes from the row and its
* values
*/
@@ -132,8 +162,11 @@ public static void processRestrictions(String pathManeuvers,
* Method getAttributesManeuversPath: Method to get Maneuvers_Path_Index
* attributes from a Maneuvers_Path_Index shape
*
- * @param rdb: Row with the content of a shapefile Maneuvers_Path_Index line
- * @return Map<String, String>: Map with attributes from the row and its values
+ * @param rdb
+ * : Row with the content of a shapefile Maneuvers_Path_Index
+ * line
+ * @return Map<String, String>: Map with attributes from the row and its
+ * values
*/
private static Map<String, String> getAttributesManeuversPath(Row rdb) {
Map<String, String> attributes = new HashMap<String, String>();
@@ -149,11 +182,13 @@ public static void processRestrictions(String pathManeuvers,
}
/**
- * Method getAttributesRestrictions: Method to get Restrictions
- * attributes from a Restrictions shape
+ * Method getAttributesRestrictions: Method to get Restrictions attributes
+ * from a Restrictions shape
*
- * @param rdb: Row with the content of a shapefile Restrictions line
- * @return Map<String, String>: Map with attributes from the row and its values
+ * @param rdb
+ * : Row with the content of a shapefile Restrictions line
+ * @return Map<String, String>: Map with attributes from the row and its
+ * values
*/
private static Map<String, String> getAttributesRestrictions(Row rdb) {
Map<String, String> attributes = new HashMap<String, String>();
@@ -169,18 +204,25 @@ public static void processRestrictions(String pathManeuvers,
}
return attributes;
}
-
+
/**
- * Method writeRestriction: return a string with the XML text to write a relation OSM
+ * Method writeRestriction: return a string with the XML text to write a
+ * relation OSM
*
- * @param idRestriction: long with the id restriction value read from the shapefile
- * @param junctID: long with the id node value read from the shapefile
- * @param from: long with the id from node value read from the shapefile
- * @param to: long with the id to node value read from the shapefile
- * @param tags: String with the XML text to write every tag from the shapefile read
+ * @param idRestriction
+ * : long with the id restriction value read from the shapefile
+ * @param junctID
+ * : long with the id node value read from the shapefile
+ * @param from
+ * : long with the id from node value read from the shapefile
+ * @param to
+ * : long with the id to node value read from the shapefile
+ * @param tags
+ * : String with the XML text to write every tag from the
+ * shapefile read
* @return String: Text with the XML content of a relation OSM
*/
- private static String writeRestriction(long idRestriction, long junctID,
+ private static String writeRestriction(long idRestriction, Integer junctID,
long from, long to, String tags) {
String relationHeader = "<relation changeset=\"1\" " + "uid=\"1\" "
+ "timestamp=\"2012-02-19T19:07:25Z\" " + "version=\"1\" "
@@ -200,17 +242,43 @@ private static String writeRestriction(long idRestriction, long junctID,
return relationHeader + memberWayFrom + memberWayTo + memberNode
+ tagType + tags + relationTail;
}
-
+
+ private static String writeRestrictionVia(long idRes,
+ List<String> memberList, long from, long to, String tags) {
+ String relationHeader = "<relation changeset=\"0\" " + "uid=\"1\" "
+ + "timestamp=\"2012-02-19T19:07:25Z\" " + "version=\"1\" "
+ + "user=\"TeleAtlas2OSM\" " + "id=\"" + idRes + "\">\n";
+
+ String memberWayFrom = "<member type=\"way\" ref=\"" + from
+ + "\" role=\"from\"/>\n";
+
+ String memberWayTo = "<member type=\"way\" ref=\"" + to
+ + "\" role=\"to\"/>\n";
+ String memberNode = "";
+ for (String idVia : memberList) {
+ memberNode += "<member type=\"way\" " + "ref=\"" + idVia + "\" "
+ + "role=\"via\"/>\n";
+ }
+ String relationTail = "</relation>\n";
+ String tagType = "<tag k=\"type\" v=\"restriction\"/>\n";
+ return relationHeader + memberWayFrom + memberWayTo + memberNode
+ + tagType + tags + relationTail;
+ }
+
/**
* Method writeTag: return a string with the XML text to write a Tag OSM
*
- * @param rt: String with the RESTTYP value
- * @param rv: String with the RESTVAL value
- * @param vt: String with the VT value
+ * @param rt
+ * : String with the RESTTYP value
+ * @param rv
+ * : String with the RESTVAL value
+ * @param vt
+ * : String with the VT value
* @return String: String qith XML text
*/
- private static String writeTag(String rt, String rv, String vt) {
- String value[] = new String[2];
+ private static List<String> writeTag(String rt, String rv, String vt) {
+ List<String> list = new LinkedList<String>();
+ List<String[]> value = null;
String tagRestriction = "";
String tagExcept = "";
if (rt.equals("6Z") || rt.equals("TR") || rt.equals("4B")) {
@@ -230,23 +298,28 @@ private static String writeTag(String rt, String rv, String vt) {
} else if (rt.equals("DF") || rt.equals("6Q")) {
value = checkDF6Q(rv, vt);
}
- if (value[0] != "") {
- tagRestriction = "<tag k=\"restriction\" v =\"" + value[0]
- + "\"/>\n";
- }
- if (value[1] != "") {
- tagExcept = "<tag k=\"except\" v=\"" + value[1] + "\"/>\n";
+ for (String[] val : value) {
+ if (val[0] != "") {
+ tagRestriction = "<tag k=\"restriction\" v =\"" + val[0]
+ + "\"/>\n";
+ }
+ if (val[1] != "") {
+ tagExcept = "<tag k=\"except\" v=\"" + val[1] + "\"/>\n";
+ }
+ list.add(tagRestriction + tagExcept);
}
-
}
- return tagRestriction + tagExcept;
+ return list;
}
/**
- * Method checkVT: Method to check the VT value and return the string with the equivalent OSM VT value
+ * Method checkVT: Method to check the VT value and return the string with
+ * the equivalent OSM VT value
*
- * @param valueIN: String with the previous VT
- * @param vt: String with the VT read from the shapefile
+ * @param valueIN
+ * : String with the previous VT
+ * @param vt
+ * : String with the VT read from the shapefile
* @return String: String with the OSM VT value
*/
private static String checkVT(String valueIN, String vt) {
@@ -294,56 +367,81 @@ private static String checkVT(String valueIN, String vt) {
}
/**
- * Method checkBlank: Method to check if the RESTVALUE is blank,
- * if is blank the OSM RESTVAL value should be 'no_straight_on'.
+ * Method checkBlank: Method to check if the RESTVALUE is blank, if is blank
+ * the OSM RESTVAL value should be 'no_straight_on'.
*
- * @param rv: String with the RESTVALUE value read from the shapefile
- * @param vt: String with the VT value read from the shapefile
- * @return String[]: String Array with the restriction tag value and the except tag value
+ * @param rv
+ * : String with the RESTVALUE value read from the shapefile
+ * @param vt
+ * : String with the VT value read from the shapefile
+ * @return String[]: String Array with the restriction tag value and the
+ * except tag value
*/
- private static String[] checkBlank(String rv, String vt) {
+ private static List<String[]> checkBlank(String rv, String vt) {
+ List<String[]> list = new LinkedList<String[]>();
String value[] = new String[2];
value[0] = "no_straight_on";
value[1] = "";
// Check VT value
value[1] = checkVT(value[1], vt);
- return value;
+ list.add(value);
+ return list;
}
/**
* Method checkBlank: Method to check if the RESTVALUE is DF or 6Q
*
- * @param rv: String with the RESTVALUE value read from the shapefile
- * @param vt: String with the VT value read from the shapefile
- * @return String[]: String Array with the restriction tag value and the except tag value
+ * @param rv
+ * : String with the RESTVALUE value read from the shapefile
+ * @param vt
+ * : String with the VT value read from the shapefile
+ * @return String[]: String Array with the restriction tag value and the
+ * except tag value
*/
- private static String[] checkDF6Q(String rv, String vt) {
+ private static List<String[]> checkDF6Q(String rv, String vt) {
+ List<String[]> list = new LinkedList<String[]>();
String value[] = new String[2];
// Check RESTRVAL value
if (rv.equals("2")) {
value[0] = "no_entry";
value[1] = "";
+ // Check VT value
+ value[1] = checkVT(value[1], vt);
+ list.add(value);
} else if (rv.equals("3")) {
value[0] = "no_exit";
value[1] = "";
+ // Check VT value
+ value[1] = checkVT(value[1], vt);
+ list.add(value);
} else if (rv.equals("4")) {
- // TODO Two restrictions
- value[0] = "";
+ value[0] = "no_entry";
+ value[1] = "";
+ // Check VT value
+ value[1] = checkVT(value[1], vt);
+ list.add(value);
+ value = new String[2];
+ value[0] = "no_exit";
value[1] = "";
+ // Check VT value
+ value[1] = checkVT(value[1], vt);
+ list.add(value);
}
- // Check VT value
- value[1] = checkVT(value[1], vt);
- return value;
+ return list;
}
/**
* Method checkBlank: Method to check if the RESTVALUE is 8I
*
- * @param rv: String with the RESTVALUE value read from the shapefile
- * @param vt: String with the VT value read from the shapefile
- * @return String[]: String Array with the restriction tag value and the except tag value
+ * @param rv
+ * : String with the RESTVALUE value read from the shapefile
+ * @param vt
+ * : String with the VT value read from the shapefile
+ * @return String[]: String Array with the restriction tag value and the
+ * except tag value
*/
- private static String[] check8I(String rv, String vt) {
+ private static List<String[]> check8I(String rv, String vt) {
+ List<String[]> list = new LinkedList<String[]>();
String value[] = new String[2];
// Check RESTRVAL value
if (rv.equals("0")) {
@@ -355,33 +453,43 @@ private static String checkVT(String valueIN, String vt) {
}
// Check VT value
value[1] = checkVT(value[1], vt);
- return value;
+ list.add(value);
+ return list;
}
/**
* Method checkBlank: Method to check if the RESTVALUE is SR
*
- * @param rv: String with the RESTVALUE value read from the shapefile
- * @param vt: String with the VT value read from the shapefile
- * @return String[]: String Array with the restriction tag value and the except tag value
+ * @param rv
+ * : String with the RESTVALUE value read from the shapefile
+ * @param vt
+ * : String with the VT value read from the shapefile
+ * @return String[]: String Array with the restriction tag value and the
+ * except tag value
*/
- private static String[] checkSR(String rv, String vt) {
+ private static List<String[]> checkSR(String rv, String vt) {
+ List<String[]> list = new LinkedList<String[]>();
String value[] = new String[2];
value[0] = "no_entry";
value[1] = "psv";
// Check VT value
value[1] = checkVT(value[1], vt);
- return value;
+ list.add(value);
+ return list;
}
/**
* Method checkBlank: Method to check if the RESTVALUE is RB
*
- * @param rv: String with the RESTVALUE value read from the shapefile
- * @param vt: String with the VT value read from the shapefile
- * @return String[]: String Array with the restriction tag value and the except tag value
+ * @param rv
+ * : String with the RESTVALUE value read from the shapefile
+ * @param vt
+ * : String with the VT value read from the shapefile
+ * @return String[]: String Array with the restriction tag value and the
+ * except tag value
*/
- private static String[] checkRB(String rv, String vt) {
+ private static List<String[]> checkRB(String rv, String vt) {
+ List<String[]> list = new LinkedList<String[]>();
String value[] = new String[2];
// Check RESTRVAL value
if (rv.equals("1") || rv.equals("3")) {
@@ -393,50 +501,60 @@ private static String checkVT(String valueIN, String vt) {
}
// Check VT value
value[1] = checkVT(value[1], vt);
- return value;
+ list.add(value);
+ return list;
}
/**
* Method checkBlank: Method to check if the RESTVALUE is BP
*
- * @param rv: String with the RESTVALUE value read from the shapefile
- * @param vt: String with the VT value read from the shapefile
- * @return String[]: String Array with the restriction tag value and the except tag value
+ * @param rv
+ * : String with the RESTVALUE value read from the shapefile
+ * @param vt
+ * : String with the VT value read from the shapefile
+ * @return String[]: String Array with the restriction tag value and the
+ * except tag value
*/
- private static String[] checkBP(String rv, String vt) {
+ private static List<String[]> checkBP(String rv, String vt) {
+ List<String[]> list = new LinkedList<String[]>();
String value[] = new String[2];
// Check RESTRVAL value
if (rv.equals("11") || rv.equals("13") || rv.equals("23")) {
value[0] = "no_entry";
value[1] = "psv";
+
} else if (rv.equals("1") || rv.equals("2") || rv.equals("12")
|| rv.equals("22")) {
value[0] = "no_entry";
value[1] = "";
}
value[1] = checkVT(value[1], vt);
-
- return value;
+ list.add(value);
+ return list;
}
/**
- * Method getSequence: Method to get the sequence of TRPLIDs in order
- * o obtain the source and target way
+ * Method getSequence: Method to get the sequence of TRPLIDs in order o
+ * obtain the source and target way
*
- * @param id: long with the id restriction value to compare with the ManeuversPath id
- * @param path: String with the Maneuvers_Path_Index path
- * @return List<String>: List with the ids from source and target ways
+ * @param id
+ * : long with the id restriction value to compare with the
+ * ManeuversPath id
+ * @param path
+ * : String with the Maneuvers_Path_Index path
+ * @return List<String>: List with the ids from source and target ways
*/
private static List<String> getSequence(long id, String path) {
List<String> trpelid = new LinkedList<String>();
ShpFiles shpFile = null;
boolean useMemoryMapped = false;
Row rdb = null;
+ DbaseFileReader dbfilereader = null;
Map<String, String> attributes = null;
try {
shpFile = new ShpFiles(path);
- DbaseFileReader dbfilereader = new DbaseFileReader(shpFile,
- useMemoryMapped, Charset.defaultCharset());
+ dbfilereader = new DbaseFileReader(shpFile, useMemoryMapped,
+ Charset.defaultCharset());
while (dbfilereader.hasNext()) {
rdb = dbfilereader.readRow();
attributes = getAttributesManeuversPath(rdb);
@@ -449,28 +567,39 @@ private static String checkVT(String valueIN, String vt) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
+ } finally {
+ try {
+ dbfilereader.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
return trpelid;
}
/**
- * Method getRestriction: Method to get a XML text with the equivalent OSM tag value
+ * Method getRestriction: Method to get a XML text with the equivalent OSM
+ * tag value
*
- * @param id: long with the id restriction value to compare with the ManeuversPath id
- * @param path: String with the Restrictions path
+ * @param id
+ * : long with the id restriction value to compare with the
+ * ManeuversPath id
+ * @param path
+ * : String with the Restrictions path
* @return
*/
- private static String getRestriction(long id, String path) {
- String rest = "";
+ private static List<String> getRestriction(long id, String path) {
+ List<String> rest = new LinkedList<String>();
ShpFiles shpFile = null;
boolean useMemoryMapped = false;
+ DbaseFileReader dbfilereader = null;
Row rdb = null;
Map<String, String> attributes = null;
try {
shpFile = new ShpFiles(path);
- DbaseFileReader dbfilereader = new DbaseFileReader(shpFile,
- useMemoryMapped, Charset.defaultCharset());
+ dbfilereader = new DbaseFileReader(shpFile, useMemoryMapped,
+ Charset.defaultCharset());
while (dbfilereader.hasNext()) {
rdb = dbfilereader.readRow();
attributes = getAttributesRestrictions(rdb);
@@ -483,7 +612,7 @@ private static String getRestriction(long id, String path) {
String resttyp = attributes.get("RESTRTYP");
String restval = attributes.get("RESTRVAL");
String vt = attributes.get("VT");
- rest = writeTag(resttyp, restval, vt);
+ rest.addAll(writeTag(resttyp, restval, vt));
}
}
}
@@ -491,6 +620,12 @@ private static String getRestriction(long id, String path) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
+ } finally {
+ try {
+ dbfilereader.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
return rest;
}
View
28 importer/src/main/java/org/gofleet/importer/teleatlas/ShapeToOSM.java
@@ -43,8 +43,6 @@
public class ShapeToOSM {
- private static long ref = 1;
-
public static void main(final String[] args) {
try {
@@ -56,13 +54,19 @@ public static void main(final String[] args) {
"tempNodesFromWays", null);
final File tempRestrictions = File.createTempFile(
"tempRestrictions", null);
+
+ long timeNode = System.currentTimeMillis();
+ System.out.println("Start processNodes at: " + new Date(System.currentTimeMillis()));
+ NodeReader.processNodes(args[1], tempNodes);
+ System.out.println("Finished processNodes at: " + new Date(System.currentTimeMillis()));
+ System.out.println("Total Time in process nodes: " + (System.currentTimeMillis() - timeNode) / 1000 + " sec");
ExecutorService executor = Executors.newFixedThreadPool(10);
Thread t = new Thread() {
public void run() {
RestrictionReader.processRestrictions(args[2], args[3],
- args[4], tempRestrictions);
+ args[4], tempRestrictions, args[6]);
};
};
@@ -72,17 +76,17 @@ public void run() {
};
};
- Thread tnode = new Thread() {
- public void run() {
- NodeReader.processNodes(args[1], tempNodes);
- };
- };
+// Thread tnode = new Thread() {
+// public void run() {
+// NodeReader.processNodes(args[1], tempNodes);
+// };
+// };
long time = System.currentTimeMillis();
System.out.println("Start at: " + new Date(System.currentTimeMillis()));
executor.execute(t);
executor.execute(tway);
- executor.execute(tnode);
+ //executor.execute(tnode);
executor.shutdown();
@@ -100,6 +104,8 @@ public void run() {
// Delete temporal file
tempWays.delete();
tempNodes.delete();
+ tempNodesFromWays.delete();
+ tempRestrictions.delete();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ShapefileException e) {
@@ -160,8 +166,10 @@ public static void readToWrite(FileReader fr, FileWriter fw) {
String linea;
try {
br = new BufferedReader(fr);
- while ((linea = br.readLine()) != null)
+ while ((linea = br.readLine()) != null){
fw.write(linea);
+ fw.write('\n');
+ }
} catch (IOException e) {
e.printStackTrace();
}
View
121 importer/src/main/java/org/gofleet/importer/teleatlas/WayReader.java
@@ -1,31 +1,32 @@
package org.gofleet.importer.teleatlas;
+
/**
-* Copyright (C) 2012, Emergya (http://www.emergya.com)
-*
-* @author <a href="mailto:marcos@emergya.com">Moisés Arcos Santiago</a>
-*
-* This file is part of GoFleetLS
-*
-* This software is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This software 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 library; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*
-* As a special exception, if you link this library with other files to
-* produce an executable, this library does not by itself cause the
-* resulting executable to be covered by the GNU General Public License.
-* This exception does not however invalidate any other reasons why the
-* executable file might be covered by the GNU General Public License.
-*/
+ * Copyright (C) 2012, Emergya (http://www.emergya.com)
+ *
+ * @author <a href="mailto:marcos@emergya.com">Moisés Arcos Santiago</a>
+ *
+ * This file is part of GoFleetLS
+ *
+ * This software is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, if you link this library with other files to
+ * produce an executable, this library does not by itself cause the
+ * resulting executable to be covered by the GNU General Public License.
+ * This exception does not however invalidate any other reasons why the
+ * executable file might be covered by the GNU General Public License.
+ */
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@@ -46,12 +47,12 @@
import com.vividsolutions.jts.geom.MultiLineString;
public class WayReader {
-
- private static long ref = 1;
-
+
+ private static long value = 57240000000000l;
+ private static Map<Long, Integer> idMap;
+
/**
- * Method processWays: write in a temporal file the ways in
- * a path
+ * Method processWays: write in a temporal file the ways in a path
*
* @param pathWays
* : String with the shapefile Networks path
@@ -61,7 +62,9 @@
* : String with the file path to write the nodes XML text
*
*/
- public static void processWays(String pathWays, File tempWays, File tempNodes){
+ public static void processWays(String pathWays, File tempWays,
+ File tempNodes) {
+ idMap = NodeReader.getIDMap();
ShpFiles shpFile = null;
boolean useMemoryMapped = false;
GeometryFactory gf = new GeometryFactory();
@@ -77,10 +80,13 @@ public static void processWays(String pathWays, File tempWays, File tempNodes){
frWays = new FileWriter(tempWays);
frNodes = new FileWriter(tempNodes);
shpFile = new ShpFiles(pathWays);
- dbfilereader = new DbaseFileReader(shpFile, useMemoryMapped,Charset.defaultCharset());
- shapefilereader = new ShapefileReader(shpFile, true,useMemoryMapped, gf);
+ dbfilereader = new DbaseFileReader(shpFile, useMemoryMapped,
+ Charset.defaultCharset());
+ shapefilereader = new ShapefileReader(shpFile, true,
+ useMemoryMapped, gf);
String lon = "";
String lat = "";
+ int idRef = idMap.size() + 1000;
while (dbfilereader.hasNext() || shapefilereader.hasNext()) {
// Define a list object with the lonlat nodes
List<String> nodes = new LinkedList<String>();
@@ -100,13 +106,13 @@ public static void processWays(String pathWays, File tempWays, File tempNodes){
lon = Double.toString(geom[i].x);
lat = Double.toString(geom[i].y);
// Add to tempWays file
- String node = " <nd ref=\"" + ref + "\"/>\n";
+ String node = " <nd ref=\"" + idRef + "\"/>\n";
nodes.add(node);
// Add to tempNodes file
if (tempNodes.exists()) {
- NodeReader.writeNodes(frNodes, ref, lat, lon);
+ NodeReader.writeNodes(frNodes, idRef, lat, lon, 1);
}
- ref++;
+ idRef++;
}
}
}
@@ -123,7 +129,7 @@ public static void processWays(String pathWays, File tempWays, File tempNodes){
frWays.flush();
} catch (IOException e) {
e.printStackTrace();
- }finally {
+ } finally {
try {
frWays.close();
frNodes.close();
@@ -134,11 +140,13 @@ public static void processWays(String pathWays, File tempWays, File tempNodes){
}
}
}
-
+
/**
- * Method getAttributesManeuvers: Method to get Network attributes from a Network shape
+ * Method getAttributesManeuvers: Method to get Network attributes from a
+ * Network shape
*
- * @param rdb: Row with the content of a shapefile Network line
+ * @param rdb
+ * : Row with the content of a shapefile Network line
* @return Map<String, String>: Map with attributes from the row and its
* values
*/
@@ -200,18 +208,24 @@ public static void processWays(String pathWays, File tempWays, File tempNodes){
}
return attributes;
}
-
+
/**
- * Method writeWay: return a string with the XML text to write a way in a OSM format
+ * Method writeWay: return a string with the XML text to write a way in a
+ * OSM format
*
- * @param atributos: Map with the attributes value read from the Network shapefile
- * @param nodes: List with the nodes to add to the XML
+ * @param atributos
+ * : Map with the attributes value read from the Network
+ * shapefile
+ * @param nodes
+ * : List with the nodes to add to the XML
* @return String: String with the XML text
*/
public static String writeWay(Map<String, String> atributos,
List<String> nodes) {
String way = "<way";
- way += " id=\"" + atributos.get("ID") + "\"";
+ long idWay = Long.valueOf(atributos.get("ID"));
+ idWay = idWay - value;
+ way += " id=\"" + idWay + "\"";
if (!atributos.containsKey("user")) {
way += " user=\"teleAtlas2osm\"";
}
@@ -228,17 +242,22 @@ public static String writeWay(Map<String, String> atributos,
way += " version=\"1\"";
}
if (!atributos.containsKey("changeset")) {
- way += " changeset=\"1\"";
+ way += " changeset=\"0\"";
}
way += ">\n";
- way += " <nd ref=\"" + atributos.get("F_JNCTID") + "\"/>\n";
+ // Change the type of the id nodes, because it must be an Integer
+ String from_junct_id = atributos.get("F_JNCTID");
+ String to_junct_id = atributos.get("T_JNCTID");
+ Integer idValueFrom = idMap.get(from_junct_id);
+ Integer idValueTo = idMap.get(to_junct_id);
+ way += " <nd ref=\"" + idValueFrom + "\"/>\n";
// Add the nodes from geometry
if (!nodes.isEmpty()) {
for (String s : nodes) {
way += s;
}
}
- way += " <nd ref=\"" + atributos.get("T_JNCTID") + "\"/>\n";
+ way += " <nd ref=\"" + idValueTo + "\"/>\n";
String frc = getFRC(atributos.get("FRC"));
way += " <tag k=\"highway\" v=\"" + frc + "\"/>\n";
way += " <tag k=\"name\" v=\"" + atributos.get("NAME") + "\"/>\n";
@@ -247,7 +266,7 @@ public static String writeWay(Map<String, String> atributos,
way += "</way>\n";
return way;
}
-
+
/**
* Method getFRC: Get a osm format string with the FRC value
*
@@ -279,7 +298,7 @@ private static String getFRC(String parameter) {
}
return frc;
}
-
+
/**
* Method getOneWay: Get a osm format string with the ONEWAY value
*
Please sign in to comment.
Something went wrong with that request. Please try again.