Files
artloglaby/java/org/artisanlogiciel/osm/convert/OsmToDrawing.java
philippe lhardy 8af19bdb59 first .osm format import
- import osm convert it to Drawing and use it as resolved path.
- Not ready , first test over lab/valbonne_oct_2020.osm
2020-10-31 15:44:23 +01:00

60 lines
1.4 KiB
Java

package org.artisanlogiciel.osm.convert;
import org.artisanlogiciel.graphics.Drawing;
import org.artisanlogiciel.graphics.DrawingLine;
import org.artisanlogiciel.osm.Node;
import org.artisanlogiciel.osm.NodeRef;
import org.artisanlogiciel.osm.Way;
import java.awt.*;
import java.util.List;
/**
* Take a way with resolved ref ( ie with NodeRef having non null getNode() )
* and create a Drawing from it.
*/
public class OsmToDrawing {
double refx = 0;
double refy = 0;
int mulx = 1;
int muly = 1;
public OsmToDrawing()
{
}
public OsmToDrawing(int mulx, int muly) {
this.mulx = mulx;
this.muly = muly;
}
public OsmToDrawing(double refx, double refy, int mulx, int muly) {
this.refx = refx;
this.refy = refy;
this.mulx = mulx;
this.muly = muly;
}
public DrawingLine getDrawingLine(Way way)
{
DrawingLine drawingLine = new DrawingLine();
for (NodeRef nr : way.getNdlist())
{
Node node = nr.getNode();
drawingLine.addPoint(new Point((int) ( (node.getLat() - refx)* mulx ) , (int) ( (node.getLon() - refy ) * muly) ));
}
return drawingLine;
}
public Drawing getDrawing(List<Way> ways)
{
Drawing drawing = new Drawing();
for (Way way : ways) {
drawing.addLine(getDrawingLine(way));
}
return drawing;
}
}