Hi,
i've been trying to patch shp-to-osm today. I've added "--maxnodes <NODES>" feature to the command line.
I use common-cli-1.1.jar.

So here my svn diff:
- osm-api-src.diff (removing @Override because it doesn't compile on Eclipse with OpenJDK 6)
- shp-to-osm-src.diff

Also here:
http://svn.progysm.com/svn/progysm/geobaseNHN2osm/shp-to-osm/

I'm currently tring to upload NHN_02LE000_1_1_HD_WATERBODY_2 with --maxnodes=30000. The first import of 8 (http://www.openstreetmap.org/browse/changeset/2008704) works.
2/8 or changeset 2008832 is currently uploading.

Filesize are around 2 and 3 MB.

--
Yan Morin
Consultant en Logiciel Libre de Progysm
[email protected]
http://www.progysm.com/
819 499-0616

Index: main/java/osm/OSMFile.java
===================================================================
--- main/java/osm/OSMFile.java	(revision 48)
+++ main/java/osm/OSMFile.java	(working copy)
@@ -100,17 +100,14 @@
             prims = primitives;
         }
 
-        @Override
         public boolean hasNext() {
             return (i < prims.length) && (prims[i] != null);
         }
 
-        @Override
         public P next() {
             return prims[i++];
         }
 
-        @Override
         public void remove() {
             return;
         }
Index: main/java/Main.java
===================================================================
--- main/java/Main.java	(revision 48)
+++ main/java/Main.java	(working copy)
@@ -5,6 +5,14 @@
 
 import org.apache.commons.lang.StringEscapeUtils;
 
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.HelpFormatter;
+
 /**
  * @author Ian Dees
  * 
@@ -15,31 +23,88 @@
      * @param args
      */
     public static void main(String[] args) {
+    	
+    	String shpFileName = "";
+    	String rulesFileName = "rules.txt";
+    	String osmFileName = "output.osm";
+    	
+        boolean keepOnlyTaggedWays = false;
+        int maxNodes = 50000;
+        
+        boolean commandLineIsValid = false;
 
-        File shpFile;
-        File osmFile;
-        RuleSet rules;
+        CommandLineParser parser = new GnuParser();
+        Options options = new Options();
+        options.addOption ("t", false, "Keep only tagged Ways");
+        options.addOption ( OptionBuilder.withLongOpt("maxnodes")
+        	.withDescription("Maximum NODES by files, default is 50000, [100-50000]")
+        	.withArgName("NODES")
+        	.hasArgs(1)
+        	.create()
+        );
+        
         try {
-            shpFile = new File(args[0]);
-            rules = readFileToRulesSet(new File(args[1]));
-            osmFile = new File(args[2]);
-            
-            boolean keepOnlyTaggedWays = false;
-            if(args.length == 4 && "-t".equals(args[3])) {
-                keepOnlyTaggedWays  = true;
-            }
-
-            ShpToOsmConverter conv = new ShpToOsmConverter(shpFile, rules, osmFile, keepOnlyTaggedWays);
-            conv.go();
-        } catch (IOException e) {
-            System.err.println("java -cp shp-to-osm.jar Main <input shapefile name> <input rules file name> <output osm file name> [-t]");
-            e.printStackTrace();
+        	CommandLine line = parser.parse( options, args, false );
+        	if (line.hasOption("t")) {
+        		keepOnlyTaggedWays = true;
+        	}
+        	if (line.hasOption("maxnodes")) {
+        		String maxNodesString = line.getOptionValue("maxnodes");
+        		try {
+        			maxNodes = Integer.parseInt(maxNodesString);
+        		} catch(NumberFormatException nfe) {
+        			maxNodes = 50000;
+        		}
+        	}
+        	shpFileName = line.getOptionValue("shapefile");
+        	String[] filenames = line.getArgs();
+        	switch(filenames.length) {
+        	case 3:
+        		shpFileName = filenames[2];
+        	case 2:
+        		rulesFileName = filenames[1];
+        	case 1:
+        		commandLineIsValid = true;
+        		shpFileName = filenames[0];
+        	}
+        	
+        } catch(ParseException exp) {
+        	System.err.println("Unexepected command line parsing exception " + exp.getMessage());
         }
         
+        if (!commandLineIsValid) {
+        	printUsage(options);
+        } else {
+	        File shpFile;
+	        File osmFile;
+	        RuleSet rules;
+	
+	        try {
+	            shpFile = new File(shpFileName);
+	            rules = readFileToRulesSet(new File(rulesFileName));
+	            osmFile = new File(osmFileName);
+	            
+	            ShpToOsmConverter conv = new ShpToOsmConverter(shpFile, rules, osmFile, keepOnlyTaggedWays, maxNodes);
+	            conv.go();
+	        } catch (IOException e) {
+	        	printUsage(options);
+	            e.printStackTrace();
+	        }
+        }
+        
         // ShpToOsmGUI g = new ShpToOsmGUI();
         // g.start();
 
     }
+    
+    private static void printUsage(Options options) {
+    	String cmd = "java -cp shp-to-osm.jar Main [-t] [--maxnodes 50000] <input shapefile name> [<input rules file name> [<output osm file name>]]";
+    	String header = " <input shapefile name> a .shp filename\n" + 
+    	                " <input rules file name> default is rules.txt\n" + 
+    	                " <output osm file name> default is output.osm";
+    	HelpFormatter formatter = new HelpFormatter();
+    	formatter.printHelp(cmd, header, options, null);
+    }
 
     /**
      * @param file
Index: main/java/ShpToOsmConverter.java
===================================================================
--- main/java/ShpToOsmConverter.java	(revision 48)
+++ main/java/ShpToOsmConverter.java	(working copy)
@@ -46,9 +46,6 @@
 import java.util.List;
 import java.util.Map;
 
-import javax.swing.event.ListSelectionEvent;
-
-
 public class ShpToOsmConverter {
 
     private static final int MAX_NODES_IN_WAY = 2000;
@@ -59,19 +56,27 @@
     private RuleSet ruleset;
     private boolean onlyIncludeTaggedPrimitives;
     private int filesCreated = 0;
+    private int maxElements = 0;
     private static int elements;
 
     /**
      * @param shpFile
      * @param rules
      * @param osmFile
+     * @param onlyIncludeTaggedPrim 
+     * @param maxNodes
      */
-    public ShpToOsmConverter(File shpFile, RuleSet rules, File osmFile, boolean onlyIncludeTaggedPrim) {
+    public ShpToOsmConverter(File shpFile, RuleSet rules, File osmFile, boolean onlyIncludeTaggedPrim, int maxNodes) {
         inputFile = shpFile;
         outputFile = osmFile;
         
         ruleset = rules;
         onlyIncludeTaggedPrimitives = onlyIncludeTaggedPrim;
+		if (maxNodes < 100 || maxNodes > MAX_ELEMENTS) {
+			maxElements = MAX_ELEMENTS;
+		} else {
+			maxElements = maxNodes;
+		}
     }
 
     /**
@@ -131,7 +136,7 @@
                             
                             int approxElementsThatWillBeAdded = (int) (rawGeom.getNumPoints() * LOADING_FACTOR);
                             System.err.println("Approx new points: " + approxElementsThatWillBeAdded + "  Total so far: " + elements);
-                            if(elements > 0 && elements + approxElementsThatWillBeAdded > MAX_ELEMENTS) {
+                            if(elements > 0 && elements + approxElementsThatWillBeAdded > maxElements) {
                                 saveOsmOut(osmOut);
                                 osmOut = new OSMFile();
                                 filesCreated++;
begin:vcard
fn:Yan Morin
n:Morin;Yan
org:ProgYSM
adr;quoted-printable:;;417, rue du Portage, app. 17;Mont-Laurier;Qu=C3=A9bec;J9L 2A3;Canada
email;internet:[email protected]
title:Consultant en Logiciel Libre
tel;work:819-499-0616
note;quoted-printable:Consultation pour les Logiciels Libres=0D=0A=
	Programmation Web=0D=0A=
	Programmation XUL, Java, C++=0D=0A=
	Scripting Linux=0D=0A=
	Support technique Linux=0D=0A=
	Formation Web/Linux/Programmation
url:http://www.progysm.com/
version:2.1
end:vcard

_______________________________________________
Talk-ca mailing list
[email protected]
http://lists.openstreetmap.org/listinfo/talk-ca

Reply via email to