5
5
6
6
package org .geogit .osm .cli .commands ;
7
7
8
+ import static org .geogit .osm .internal .OSMUtils .NODE_TYPE_NAME ;
9
+ import static org .geogit .osm .internal .OSMUtils .WAY_TYPE_NAME ;
10
+ import static org .geogit .osm .internal .OSMUtils .nodeType ;
11
+ import static org .geogit .osm .internal .OSMUtils .wayType ;
12
+
8
13
import java .io .File ;
9
14
import java .io .IOException ;
10
15
import java .net .URISyntaxException ;
58
63
import org .geogit .repository .Repository ;
59
64
import org .geogit .repository .StagingArea ;
60
65
import org .geogit .repository .WorkingTree ;
61
- import org .geotools .data .DataUtilities ;
62
66
import org .geotools .feature .simple .SimpleFeatureBuilder ;
63
- import org .geotools .referencing .CRS ;
64
67
import org .opengis .feature .Feature ;
65
68
import org .opengis .feature .simple .SimpleFeature ;
66
69
import org .opengis .feature .simple .SimpleFeatureType ;
67
- import org .opengis .referencing .crs .CoordinateReferenceSystem ;
68
70
69
71
import com .beust .jcommander .Parameters ;
70
72
import com .beust .jcommander .ParametersDelegate ;
91
93
@ Parameters (commandNames = "import-history" , commandDescription = "Import OpenStreetmap history" )
92
94
public class OSMHistoryImport extends AbstractCommand implements CLICommand {
93
95
94
- /** FeatureType namespace */
95
- private static final String NAMESPACE = "www.openstreetmap.org" ;
96
-
97
- /** NODE */
98
- private static final String NODE_TYPE_NAME = "node" ;
99
-
100
- /** WAY */
101
- private static final String WAY_TYPE_NAME = "way" ;
102
-
103
96
private static final GeometryFactory GEOMF = new GeometryFactory ();
104
97
105
98
@ ParametersDelegate
@@ -463,44 +456,6 @@ private String featurePath(Change change) {
463
456
return NodeRef .appendChild (WAY_TYPE_NAME , fid );
464
457
}
465
458
466
- private static SimpleFeatureType NodeType ;
467
-
468
- private static SimpleFeatureType WayType ;
469
-
470
- // private static SimpleFeatureType RelationType;
471
-
472
- private synchronized static SimpleFeatureType nodeType () {
473
- if (NodeType == null ) {
474
- String typeSpec = "visible:Boolean,version:Integer,timestamp:java.lang.Long,tags:String,location:Point:srid=4326" ;
475
- try {
476
- SimpleFeatureType type = DataUtilities .createType (NAMESPACE , NODE_TYPE_NAME ,
477
- typeSpec );
478
- boolean longitudeFirst = true ;
479
- CoordinateReferenceSystem forceLonLat = CRS .decode ("EPSG:4326" , longitudeFirst );
480
- NodeType = DataUtilities .createSubType (type , null , forceLonLat );
481
- } catch (Exception e ) {
482
- throw Throwables .propagate (e );
483
- }
484
- }
485
- return NodeType ;
486
- }
487
-
488
- private synchronized static SimpleFeatureType wayType () {
489
- if (WayType == null ) {
490
- String typeSpec = "visible:Boolean,version:Integer,timestamp:java.lang.Long,tags:String,way:LineString:srid=4326" ;
491
- try {
492
- SimpleFeatureType type = DataUtilities .createType (NAMESPACE , NODE_TYPE_NAME ,
493
- typeSpec );
494
- boolean longitudeFirst = true ;
495
- CoordinateReferenceSystem forceLonLat = CRS .decode ("EPSG:4326" , longitudeFirst );
496
- WayType = DataUtilities .createSubType (type , null , forceLonLat );
497
- } catch (Exception e ) {
498
- throw Throwables .propagate (e );
499
- }
500
- }
501
- return WayType ;
502
- }
503
-
504
459
private static final RevFeatureType NODE_REV_TYPE = RevFeatureType .build (nodeType ());
505
460
506
461
private static final RevFeatureType WAY_REV_TYPE = RevFeatureType .build (wayType ());
@@ -514,13 +469,20 @@ private static SimpleFeature toFeature(Primitive feature, Geometry geom) {
514
469
builder .set ("visible" , Boolean .valueOf (feature .isVisible ()));
515
470
builder .set ("version" , Integer .valueOf (feature .getVersion ()));
516
471
builder .set ("timestamp" , Long .valueOf (feature .getTimestamp ()));
472
+ builder .set ("changeset" , Long .valueOf (feature .getChangesetId ()));
517
473
518
474
String tags = buildTagsString (feature .getTags ());
519
475
builder .set ("tags" , tags );
476
+
477
+ String user = feature .getUserName () + ":" + feature .getUserId ();
478
+ builder .set ("user" , user );
479
+
520
480
if (feature instanceof Node ) {
521
481
builder .set ("location" , geom );
522
482
} else if (feature instanceof Way ) {
523
483
builder .set ("way" , geom );
484
+ String nodes = buildNodesString (((Way ) feature ).getNodes ());
485
+ builder .set ("nodes" , nodes );
524
486
} else {
525
487
throw new IllegalArgumentException ();
526
488
}
@@ -554,4 +516,17 @@ private static String buildTagsString(Map<String, String> tags) {
554
516
}
555
517
return sb .toString ();
556
518
}
519
+
520
+ private static String buildNodesString (List <Long > nodeIds ) {
521
+ StringBuilder sb = new StringBuilder ();
522
+ for (Iterator <Long > it = nodeIds .iterator (); it .hasNext ();) {
523
+ Long node = it .next ();
524
+ sb .append (node );
525
+ if (it .hasNext ()) {
526
+ sb .append (";" );
527
+ }
528
+ }
529
+ return sb .toString ();
530
+
531
+ }
557
532
}
0 commit comments