I'm working on a road network program, and want to display the road network as a quick visual to verify it's set up properly.
I have the coordinates of each junction, and want to convert them to one's I can use in JavaFX, eg: Canvas.
However, the coordinates for longitude are in the negatives, and I'm stuck on converting them to, say, a window of 750 x 750
I have the min & max latitude and longitude values
lowest longitude value: -122.5142235 highest longitude value: -122.3637617
lowest latitude value: 37.7082614 highest latitude value: 37.8174339
so I need to figure out how to scale the distance between each junction while maintining position and distance between the junctions, and transform it to make it able to appear on the canvas, as currently it starts at -122
Thanks in advance for any help.
I've tried using different methods such as this:
GraphicsContext gc = canvas.getGraphicsContext2D();
Double maxX = -122.3637617;
Double minX = -122.5142235;
Double maxY = 37.8174339;
Double minY = 37.7082614;
int width = 750;
int height = 750;
double xrange = maxX - minX;
double yrange = maxY - minY;
double xratio = xrange / width;
double yratio = yrange / height;
// width and height are in units of pixels
// gc is the GraphicsContext object from javafx
Affine t = new Affine();
t.appendTranslation( minX, minY );
t.appendScale( (xratio*150),(yratio*150) );
try
{
t.invert();
}
catch(NonInvertibleTransformException e )
{
throw new RuntimeException( e.getMessage(), e );
}
gc.setTransform( t );
gc.setFill(Color.BLACK);
gc.setLineWidth(1);
gc.strokeLine(-122.40351, 37.80489, -122.40345, 37.80504);
but it doesn't seem to work properly.
I've also tried this code:
Double x1 = xConversion(maxX, minX, -122.40351, width);
Double x2 = xConversion(maxX, minX, -122.40345, width);
Double y1 = yConversion(maxY, minY, 37.80489, height);
Double y2 = yConversion(maxY, minY, 37.80504, height);
Scale scale = new Scale();
scale.setX(xrange*width);
scale.setY(yrange*height);
Line line = new Line(x1, y1, x2, y2);
line.getTransforms().add(scale);
public Double xConversion(Double maxX, Double minX, Double x, int width)
{
//return (minX)+Math.abs((maxX)-(minX))*(x+0.5)/width;
return x-minX;
}
public Double yConversion(Double maxY, Double minY, Double y, int height)
{
return y-maxY;
//return (minY)+Math.abs((maxY)-(minY))*(y+0.5)/height;
}
but the best result I've got has been a square appearing, instead of a line, which is a bit wrong XD.