Index: /applications/editors/josm/plugins/pdfimport/src/pdfimport/FilePlacement.java
===================================================================
--- /applications/editors/josm/plugins/pdfimport/src/pdfimport/FilePlacement.java	(revision 24056)
+++ /applications/editors/josm/plugins/pdfimport/src/pdfimport/FilePlacement.java	(revision 24056)
@@ -0,0 +1,114 @@
+package pdfimport;
+
+import java.util.Properties;
+
+import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.projection.Projection;
+
+public class FilePlacement {
+	public Projection projection = null;
+	public double minX = 0;
+	public double maxX = 1;
+	public double minY = 0;
+	public double maxY = 1;
+
+	public double minEast = 0;
+	public double maxEast = 10000;
+	public double minNorth = 0;
+	public double maxNorth = 10000;
+
+	public void setPdfBounds(double minX, double minY, double maxX, double maxY){
+		this.minX = minX;
+		this.minY = minY;
+		this.maxX = maxX;
+		this.maxY = maxY;
+	}
+
+	public void setEastNorthBounds(double minEast, double minNorth, double maxEast, double maxNorth) {
+		this.minEast = minEast;
+		this.maxEast = maxEast;
+		this.minNorth = minNorth;
+		this.maxNorth = maxNorth;
+	}
+
+	public Properties toProperties() {
+		Properties p = new Properties();
+		if (projection != null) {
+			p.setProperty("Projection", projection.getClass().getCanonicalName());
+		}
+
+		p.setProperty("minX", Double.toString(minX));
+		p.setProperty("maxX", Double.toString(maxX));
+		p.setProperty("minY", Double.toString(minY));
+		p.setProperty("maxY", Double.toString(maxY));
+		p.setProperty("minEast", Double.toString(minEast));
+		p.setProperty("maxEast", Double.toString(maxEast));
+		p.setProperty("minNorth", Double.toString(minNorth));
+		p.setProperty("maxNorth", Double.toString(maxNorth));
+
+		return p;
+	}
+
+	public void fromProperties(Properties p){
+
+		String className = p.getProperty("Projection", null);
+		projection = null;
+
+		if (className != null) {
+			for(Projection proj: Projection.allProjections){
+				if (proj.getClass().getCanonicalName().equals(className)){
+					projection = proj;
+					break;
+				}
+			}
+		}
+
+		minX = parseProperty(p, "minX", minX);
+		maxX = parseProperty(p, "maxX", maxX);
+		minY = parseProperty(p, "minY", minY);
+		maxY = parseProperty(p, "maxY", maxY);
+
+		minEast = parseProperty(p, "minEast", minEast);
+		maxEast = parseProperty(p, "maxEast", maxEast);
+		minNorth = parseProperty(p, "minNorth", minNorth);
+		maxNorth = parseProperty(p, "maxNorth", maxNorth);
+	}
+
+	private double parseProperty(Properties p, String name, double defaultValue){
+		if (!p.containsKey(name)) {
+			return defaultValue;
+		}
+
+		String value = p.getProperty(name);
+
+		try {
+			return Double.parseDouble(value);
+		} catch (Exception e) {
+			return defaultValue;
+		}
+
+	}
+
+	public LatLon tranformCoords(double x, double y) {
+
+		if (this.projection == null){
+			return new LatLon(y/1000, x/1000);
+		}
+		else{
+			x = (x - this.minX) * (this.maxEast - this.minEast) / (this.maxX - this.minX)  + this.minEast;
+			y = (y - this.minY) * (this.maxNorth - this.minNorth) /  (this.maxY - this.minY) + this.minNorth;
+			return this.projection.eastNorth2latlon(new EastNorth(x, y));
+		}
+	}
+
+	public EastNorth reverseTransform(LatLon coor) {
+		if (this.projection == null){
+			return new EastNorth(coor.lon() * 1000, coor.lat() * 1000);
+		}
+		else{
+			return null;
+		}
+	}
+
+}
Index: /applications/editors/josm/plugins/pdfimport/src/pdfimport/LoadPdfDialog.java
===================================================================
--- /applications/editors/josm/plugins/pdfimport/src/pdfimport/LoadPdfDialog.java	(revision 24055)
+++ /applications/editors/josm/plugins/pdfimport/src/pdfimport/LoadPdfDialog.java	(revision 24056)
@@ -3,4 +3,5 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
+import java.awt.Color;
 import java.awt.Cursor;
 import java.awt.GridBagConstraints;
@@ -12,7 +13,9 @@
 import java.awt.event.WindowEvent;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.Collection;
+import java.util.Properties;
 
 import javax.swing.BorderFactory;
@@ -45,5 +48,5 @@
 	private String fileName;
 	private PathOptimizer data;
-	private final OsmBuilder builder;
+	private final FilePlacement placement;
 	private OsmDataLayer layer;
 
@@ -70,8 +73,12 @@
 	private JCheckBox mergeCloseNodesCheck;
 	private JTextField mergeCloseNodesTolerance;
+	private JCheckBox removeSmallObjectsCheck;
+	private JTextField removeSmallObjectsSize;
+	private JTextField colorFilterColor;
+	private JCheckBox colorFilterCheck;
 
 	public LoadPdfDialog() {
 
-		this.builder = new OsmBuilder();
+		this.placement = new FilePlacement();
 
 		this.buildGUI();
@@ -150,27 +157,48 @@
 		this.cancelButton = new JButton(tr("Discard"));
 
-		this.minXField = new JTextField(""+this.builder.minX);
-		this.minYField = new JTextField(""+this.builder.minY);
-		this.minEastField = new JTextField(""+this.builder.minEast);
-		this.minNorthField = new JTextField(""+this.builder.minNorth);
+		this.minXField = new JTextField(""+this.placement.minX);
+		this.minYField = new JTextField(""+this.placement.minY);
+		this.minEastField = new JTextField(""+this.placement.minEast);
+		this.minNorthField = new JTextField(""+this.placement.minNorth);
 		this.getMinButton = new JButton(tr("Take X and Y from selected node"));
 
-		this.maxXField = new JTextField(""+this.builder.maxX);
-		this.maxYField = new JTextField(""+this.builder.maxY);
-		this.maxEastField = new JTextField(""+this.builder.maxEast);
-		this.maxNorthField = new JTextField(""+this.builder.maxNorth);
+		this.maxXField = new JTextField(""+this.placement.maxX);
+		this.maxYField = new JTextField(""+this.placement.maxY);
+		this.maxEastField = new JTextField(""+this.placement.maxEast);
+		this.maxNorthField = new JTextField(""+this.placement.maxNorth);
 		this.getMaxButton = new JButton(tr("Take X and Y from selected node"));
 
 		this.debugModeCheck = new JCheckBox(tr("Debug info"));
 		this.mergeCloseNodesCheck = new JCheckBox(tr("Merge close nodes"));
-		this.mergeCloseNodesTolerance = new JTextField();
+		this.mergeCloseNodesTolerance = new JTextField("1e-6");
+
+		this.removeSmallObjectsCheck = new JCheckBox(tr("Remove objects smaller than"));
+		this.removeSmallObjectsSize = new JTextField("1");
+
+		this.colorFilterCheck = new JCheckBox(tr("Only this color"));
+		this.colorFilterColor = new JTextField("#000000");
 
 		JPanel configPanel = new JPanel(new GridBagLayout());
+		configPanel.setBorder(BorderFactory.createTitledBorder(tr("Import settings")));
 		c.gridx = 0; c.gridy = 0; c.gridwidth = 1;
 		configPanel.add(this.mergeCloseNodesCheck, c);
-		c.gridx = 1; c.gridy = 0; c.gridwidth = 1;
+		c.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.anchor = c.NORTHEAST;
+		configPanel.add(new JLabel("Tolerance :"), c);
+		c.gridx = 2; c.gridy = 0; c.gridwidth = 1; c.anchor = c.NORTHWEST;
 		configPanel.add(this.mergeCloseNodesTolerance, c);
 
-		c.gridx = 0; c.gridy = 1; c.gridwidth = 2;
+		c.gridx = 0; c.gridy = 1; c.gridwidth = 1;
+		configPanel.add(this.removeSmallObjectsCheck, c);
+		c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.anchor = c.NORTHEAST;
+		configPanel.add(new JLabel("Tolerance :"), c);
+		c.gridx = 2; c.gridy = 1; c.gridwidth = 1; c.anchor = c.NORTHWEST;
+		configPanel.add(this.removeSmallObjectsSize, c);
+
+		c.gridx = 0; c.gridy = 2; c.gridwidth = 1;
+		configPanel.add(this.colorFilterCheck, c);
+		c.gridx = 2; c.gridy = 2; c.gridwidth = 1;
+		configPanel.add(this.colorFilterColor, c);
+
+		c.gridx = 0; c.gridy = 3; c.gridwidth = 2;
 		configPanel.add(this.debugModeCheck, c);
 
@@ -241,5 +269,5 @@
 		panel.add(okCancelPanel, c);
 
-		this.setSize(400, 400);
+		this.setSize(400, 500);
 		this.setContentPane(panel);
 	}
@@ -316,4 +344,6 @@
 		}
 
+		OsmBuilder builder = new OsmBuilder(this.placement);
+
 		//zoom to new location
 		Main.map.mapView.zoomTo(builder.getWorldBounds(this.data));
@@ -356,5 +386,5 @@
 
 		LatLon ll = ((Node)selected.iterator().next()).getCoor();
-		return this.builder.reverseTransform(ll);
+		return this.placement.reverseTransform(ll);
 	}
 
@@ -453,4 +483,20 @@
 		}
 
+		if (this.colorFilterCheck.isSelected()) {
+			try {
+				String colString = this.colorFilterColor.getText().replace("#", "");
+				Color color = new Color(Integer.parseInt(colString, 16));
+				data.filterByColor(color);
+			}
+			catch (Exception e) {
+				JOptionPane
+				.showMessageDialog(
+						Main.parent,
+						tr("Could not parse color"));
+				return null;
+			}
+		}
+
+
 		if (this.mergeCloseNodesCheck.isSelected()) {
 			try {
@@ -467,7 +513,42 @@
 		}
 
-		data.optimize();
+		data.mergeSegments();
+
+		if (this.removeSmallObjectsCheck.isSelected()) {
+			try {
+				double tolerance = Double.parseDouble(this.removeSmallObjectsSize.getText());
+				data.removeSmallObjects(tolerance);
+			}
+			catch (Exception e) {
+				JOptionPane
+				.showMessageDialog(
+						Main.parent,
+						tr("Tolerance is not a number"));
+				return null;
+			}
+		}
+
+
+		data.splitLayersByPathKind();
+		data.finish();
+
+		//load saved transformation
+		File propertiesFile = new File(fileName.getAbsoluteFile()+ ".placement");
+		try {
+
+			if (propertiesFile.exists()){
+				Properties p = new Properties();
+				p.load(new FileInputStream(propertiesFile));
+				this.placement.fromProperties(p);
+				this.setTransformation();
+			}
+		}catch (Exception e){
+			e.printStackTrace();
+		}
+
 		return data;
 	}
+
+
 
 	private boolean loadTransformation() {
@@ -480,14 +561,14 @@
 		}
 
-		this.builder.projection = (Projection)this.projectionCombo.getSelectedItem();
+		this.placement.projection = (Projection)this.projectionCombo.getSelectedItem();
 
 		try
 		{
-			this.builder.setPdfBounds(
+			this.placement.setPdfBounds(
 					Double.parseDouble(this.minXField.getText()),
 					Double.parseDouble(this.minYField.getText()),
 					Double.parseDouble(this.maxXField.getText()),
 					Double.parseDouble(this.maxYField.getText()));
-			this.builder.setEastNorthBounds(
+			this.placement.setEastNorthBounds(
 					Double.parseDouble(this.minEastField.getText()),
 					Double.parseDouble(this.minNorthField.getText()),
@@ -503,10 +584,25 @@
 	}
 
+	private void setTransformation() {
+
+		this.projectionCombo.setSelectedItem(placement.projection);
+		this.minXField.setText(Double.toString(placement.minX));
+		this.maxXField.setText(Double.toString(placement.maxX));
+		this.minYField.setText(Double.toString(placement.minY));
+		this.maxYField.setText(Double.toString(placement.maxY));
+		this.minEastField.setText(Double.toString(placement.minEast));
+		this.maxEastField.setText(Double.toString(placement.maxEast));
+		this.minNorthField.setText(Double.toString(placement.minNorth));
+		this.maxNorthField.setText(Double.toString(placement.maxNorth));
+	}
+
 	private void makeLayer(String name, OsmBuilder.Mode mode) {
 		this.removeLayer();
 
-		if (builder == null) {
+		if (placement == null) {
 			return;
 		}
+
+		OsmBuilder builder = new OsmBuilder(this.placement);
 
 		DataSet data = builder.build(this.data.getLayers(), mode);
@@ -534,4 +630,5 @@
 
 	private void saveLayer(java.io.File file) {
+		OsmBuilder builder = new OsmBuilder(this.placement);
 		DataSet data = builder.build(this.data.getLayers(), OsmBuilder.Mode.Final);
 		OsmDataLayer layer = new OsmDataLayer(data, file.getName(), file);
Index: /applications/editors/josm/plugins/pdfimport/src/pdfimport/OsmBuilder.java
===================================================================
--- /applications/editors/josm/plugins/pdfimport/src/pdfimport/OsmBuilder.java	(revision 24055)
+++ /applications/editors/josm/plugins/pdfimport/src/pdfimport/OsmBuilder.java	(revision 24056)
@@ -9,5 +9,4 @@
 
 import org.openstreetmap.josm.data.Bounds;
-import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.DataSet;
@@ -16,5 +15,4 @@
 import org.openstreetmap.josm.data.osm.RelationMember;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.projection.Projection;
 
 public class OsmBuilder {
@@ -22,14 +20,5 @@
 	enum Mode {Draft, Final, Debug};
 
-	public Projection projection = null;
-	public double minX = 0;
-	public double maxX = 1;
-	public double minY = 0;
-	public double maxY = 1;
-
-	public double minEast = 0;
-	public double maxEast = 10000;
-	public double minNorth = 0;
-	public double maxNorth = 10000;
+	private final FilePlacement placement;
 
 	private String layerName;
@@ -39,26 +28,13 @@
 
 
-	public OsmBuilder()
+	public OsmBuilder(FilePlacement placement)
 	{
-	}
-
-	public void setPdfBounds(double minX, double minY, double maxX, double maxY){
-		this.minX = minX;
-		this.minY = minY;
-		this.maxX = maxX;
-		this.maxY = maxY;
-	}
-
-	public void setEastNorthBounds(double minEast, double minNorth, double maxEast, double maxNorth) {
-		this.minEast = minEast;
-		this.maxEast = maxEast;
-		this.minNorth = minNorth;
-		this.maxNorth = maxNorth;
+		this.placement = placement;
 	}
 
 
 	public Bounds getWorldBounds(PathOptimizer data) {
-		LatLon min = tranformCoords(data.bounds.getMinX(), data.bounds.getMinY());
-		LatLon max = tranformCoords(data.bounds.getMaxX(), data.bounds.getMaxY());
+		LatLon min = placement.tranformCoords(data.bounds.getMinX(), data.bounds.getMinY());
+		LatLon max = placement.tranformCoords(data.bounds.getMaxX(), data.bounds.getMaxY());
 		return new Bounds(min, max);
 	}
@@ -86,5 +62,5 @@
 		for(Point2D pt: layer.points) {
 			Node node = new Node();
-			node.setCoor(this.tranformCoords(pt.getX(), pt.getY()));
+			node.setCoor(this.placement.tranformCoords(pt.getX(), pt.getY()));
 
 			target.addPrimitive(node);
@@ -199,25 +175,3 @@
 		return "#" + s;
 	}
-
-
-	private LatLon tranformCoords(double x, double y) {
-
-		if (this.projection == null){
-			return new LatLon(y/1000, x/1000);
-		}
-		else{
-			x = (x - this.minX) * (this.maxEast - this.minEast) / (this.maxX - this.minX)  + this.minEast;
-			y = (y - this.minY) * (this.maxNorth - this.minNorth) /  (this.maxY - this.minY) + this.minNorth;
-			return this.projection.eastNorth2latlon(new EastNorth(x, y));
-		}
-	}
-
-	public EastNorth reverseTransform(LatLon coor) {
-		if (this.projection == null){
-			return new EastNorth(coor.lon() * 1000, coor.lat() * 1000);
-		}
-		else{
-			return null;
-		}
-	}
 }
Index: /applications/editors/josm/plugins/pdfimport/src/pdfimport/PathOptimizer.java
===================================================================
--- /applications/editors/josm/plugins/pdfimport/src/pdfimport/PathOptimizer.java	(revision 24055)
+++ /applications/editors/josm/plugins/pdfimport/src/pdfimport/PathOptimizer.java	(revision 24056)
@@ -1,4 +1,5 @@
 package pdfimport;
 
+import java.awt.Color;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
@@ -18,5 +19,4 @@
 	private List<LayerContents> layers;
 	public Rectangle2D bounds;
-	private final double POINT_TOLERANCE = 1e-6;
 
 	public PathOptimizer()
@@ -51,4 +51,84 @@
 		layer.multiPaths.add(p);
 	}
+
+	public void filterByColor(Color color) {
+		List<LayerContents> newLayers = new ArrayList<LayerContents>();
+		for(LayerContents l: this.layers) {
+
+			boolean good = false;
+
+			if (l.info.fill != null && l.info.fill.equals(color)) {
+				good = true;
+			}
+
+			if (l.info.stroke != null && l.info.stroke.equals(color)) {
+				good = true;
+			}
+
+			if (good) {
+				newLayers.add(l);
+			}
+		}
+		this.layers = newLayers;
+	}
+
+
+
+	public void mergeNodes(double tolerance) {
+		Map<Point2D, Point2D> pointMap = DuplicateNodesFinder.findDuplicateNodes(uniquePoints, tolerance);
+
+		for(LayerContents layer: this.layers) {
+			this.fixPoints(layer, pointMap);
+		}
+	}
+
+	public void mergeSegments() {
+		for(LayerContents layer: this.layers) {
+			this.concatenatePaths(layer);
+		}
+	}
+
+
+	public void removeSmallObjects(double tolerance) {
+		for(LayerContents layer: this.layers) {
+			this.removeSmallObjects(layer, tolerance);
+		}
+	}
+
+	public void splitLayersBySimilarShapes(double tolerance) {
+		List<LayerContents> newLayers = new ArrayList<LayerContents>();
+		for(LayerContents l: this.layers) {
+			List<LayerContents> splitResult = splitBySimilarGroups(l);
+
+			for(LayerContents ll: splitResult) {
+				newLayers.add(ll);
+			}
+		}
+		this.layers = newLayers;
+	}
+
+	public void splitLayersByPathKind() {
+		List<LayerContents> newLayers = new ArrayList<LayerContents>();
+		for(LayerContents l: this.layers) {
+			List<LayerContents> splitResult = splitBySegmentKind(l);
+
+			for(LayerContents ll: splitResult) {
+				newLayers.add(ll);
+			}
+		}
+
+		this.layers = newLayers;
+	}
+
+
+	public void finish() {
+		int nr = 0;
+		for(LayerContents layer: this.layers) {
+			layer.info.nr = nr;
+			nr++;
+			finalizeLayer(layer);
+		}
+	}
+
 
 	private LayerContents getLayer(LayerInfo info) {
@@ -72,47 +152,4 @@
 
 
-	public void mergeNodes(double tolerance) {
-		Map<Point2D, Point2D> pointMap = DuplicateNodesFinder.findDuplicateNodes(uniquePoints, POINT_TOLERANCE);
-
-		for(LayerContents layer: this.layers) {
-			this.fixPoints(layer, pointMap);
-			this.concatenatePaths(layer);
-		}
-	}
-
-	public void optimize()
-	{
-		List<LayerContents> newLayers = new ArrayList<LayerContents>();
-		/*
-		for(LayerContents l: this.layers) {
-			List<LayerContents> splitResult = splitBySimilarGroups(l);
-
-			for(LayerContents ll: splitResult) {
-				newLayers.add(ll);
-			}
-		}
-		this.layers = newLayers;
-		 */
-
-
-		newLayers = new ArrayList<LayerContents>();
-		for(LayerContents l: this.layers) {
-			List<LayerContents> splitResult = splitBySegmentKind(l);
-
-			for(LayerContents ll: splitResult) {
-				newLayers.add(ll);
-			}
-		}
-
-		this.layers = newLayers;
-		int nr = 0;
-		for(LayerContents layer: this.layers) {
-			layer.info.nr = nr;
-			nr++;
-			finalizeLayer(layer);
-		}
-	}
-
-
 	private void finalizeLayer(LayerContents layer){
 		Set<Point2D> points = new HashSet<Point2D>();
@@ -189,4 +226,49 @@
 		return newPoints;
 	}
+
+
+	private void removeSmallObjects(LayerContents layer, double tolerance) {
+		List<PdfPath> newPaths = new ArrayList<PdfPath>(layer.paths.size());
+
+		for(PdfPath path: layer.paths) {
+			boolean good = getShapeSize(path) >= tolerance;
+
+			if (good) {
+				newPaths.add(path);
+			}
+		}
+
+		layer.paths = newPaths;
+
+		List<PdfMultiPath> newMPaths = new ArrayList<PdfMultiPath>(layer.multiPaths.size());
+
+		for (PdfMultiPath mp: layer.multiPaths){
+			boolean good = true;
+			for(PdfPath path: mp.paths) {
+				good &= getShapeSize(path) >= tolerance;
+			}
+
+			if (good) {
+				newMPaths.add(mp);
+			}
+		}
+
+		layer.multiPaths = newMPaths;
+	}
+
+
+	private double getShapeSize(PdfPath path) {
+
+		Rectangle2D bounds = new Rectangle2D.Double();
+		bounds.setRect(path.points.get(0).getX(), path.points.get(0).getY(), 0,0);
+
+		for(Point2D n: path.points) {
+			bounds.add(n);
+		}
+
+		return Math.max(bounds.getWidth(), bounds.getHeight());
+	}
+
+
 
 	/**
