Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 46 additions & 13 deletions postgis-jdbc-java2d/src/main/java/examples/TestJava2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* (C) 2004 Paul Ramsey, pramsey@refractions.net
*
* (C) 2005 Markus Schaber, markus.schaber@logix-tt.com
*
* (C) 2015 Phillip Ross, phillip.w.g.ross@gmail.com
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -43,6 +45,14 @@ public class TestJava2d {

public static final Shape[] SHAPEARRAY = new Shape[0];

public static final String[][] testDataset = new String[][] {
{"point1", "POINT(10 11)"},
{"multipoint1", "MULTIPOINT(10.25 11,10.5 11,10.75 11,11 11,11.25 11,11.5 11,11.75 11,12 11)"},
{"linestring1", "LINESTRING(0 0,100 0,100 100,0 100)"},
{"linestring2", "LINESTRING(-310 110,210 110,210 210,-310 210,-310 110)"},
{"multilinestring", "MULTILINESTRING((0 0,10 10,20 0,30 10),(40 0,40 10,50 10,50 20,60 20))"},
};

static {
new Java2DWrapper(); // make shure our driver is initialized
}
Expand All @@ -58,11 +68,14 @@ public static void main(String[] args) throws ClassNotFoundException, SQLExcepti
System.exit(1);
}

Shape[] geometries = read(args[0], args[1], args[2], "SELECT " + args[4] + " FROM "
+ args[3]);

Shape[] geometries = read(args[0], args[1], args[2], "SELECT " + args[4] + " FROM " + args[3]);
if (DEBUG) {
System.err.println("read " + geometries.length + " geometries.");
}
if (geometries.length == 0) {
System.err.println("No geometries were found.");
if (DEBUG) {
System.err.println("No geometries were read.");
}
return;
}

Expand Down Expand Up @@ -91,11 +104,15 @@ static Rectangle2D calcbbox(Shape[] geometries) {
private static Shape[] read(String dburl, String dbuser, String dbpass, String query)
throws ClassNotFoundException, SQLException {
ArrayList geometries = new ArrayList();
System.out.println("Creating JDBC connection...");
if (DEBUG) {
System.err.println("Creating JDBC connection...");
}
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(dburl, dbuser, dbpass);

System.out.println("fetching geometries");
if (DEBUG) {
System.err.println("fetching geometries: " + query);
}
ResultSet r = conn.createStatement().executeQuery(query);

while (r.next()) {
Expand Down Expand Up @@ -123,17 +140,33 @@ public GisCanvas(Shape[] geometries) {

public void paint(Graphics og) {
Graphics2D g = (Graphics2D) og;

final double scaleX = (super.getWidth() - 10) / bbox.getWidth();
final double scaleY = (super.getHeight() - 10) / bbox.getHeight();

// Add 5% padding on all borders
final double paddingTop = bbox.getHeight() * 0.05;
final double paddingBottom = bbox.getHeight() * 0.05;
final double paddingLeft = bbox.getWidth() * 0.05;
final double paddingRight = bbox.getWidth() * 0.05;
// If the bounding box has negative coordinates, we need to offset by the negative coordinate
final double offsetX = (bbox.getX() < 0) ? (0 - bbox.getX()) : 0;
final double offsetY = (bbox.getY() < 0) ? (0 - bbox.getY()) : 0;
// Scale by the bounding box and padding
final double scaleX = (super.getWidth() - (paddingLeft + paddingRight)) / (bbox.getWidth());
final double scaleY = (super.getHeight() - (paddingTop + paddingBottom)) / (bbox.getHeight());
// Apply the transform parameters
AffineTransform at = new AffineTransform();
at.translate(super.getX() + 5, super.getY() + 5);
at.translate(paddingLeft, paddingTop);
at.scale(scaleX, scaleY);
at.translate(-bbox.getX(), -bbox.getY());
at.translate(offsetX, offsetY);

if (DEBUG) {
System.err.println();
System.err.println("paddingTop: " + paddingTop);
System.err.println("paddingBottom: " + paddingBottom);
System.err.println("paddingLeft: " + paddingLeft);
System.err.println("paddingRight: " + paddingRight);
System.err.println("offsetX: " + offsetX);
System.err.println("offsetY: " + offsetY);
System.err.println("scaleX: " + scaleX);
System.err.println("scaleY: " + scaleY);
System.err.println("bbox: " + bbox);
System.err.println("trans: " + at);
System.err.println("new: " + at.createTransformedShape(bbox).getBounds2D());
Expand Down Expand Up @@ -174,4 +207,4 @@ public void windowIconified(WindowEvent e) {//
public void windowOpened(WindowEvent e) {//
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,11 @@
*
* As the java.awt.Shape methods currently are implemented by using a
* java.awt.geom.GeneralPath object, they have the same semantics.
*
* BUG/TODO: MultiPoints or Points in a Geometry Collection currently don't work
* as expected, as some GeneralPath implementations throw away adjacent MoveTo
* commands as an optimization (e. G. sun 1.5 and ibm 1.5). Points thus are
* translated into MoveTo() followed by a closePath. This may change when we
* implement our own path logics. We have to evaluate whether Graphics2D renders
* a single MoveTo command as a single "brush tip", or we need the closePath()
* command nevertheless to get any drawing. Maybe we need a LineTo() to the same
* coordinages instead.
*
*
* NOTE: (Multi)Points are translated into a sequence of single MoveTo and LineTo
* commands, but WITHOUT a closePath command. When rendering with a stroke that
* is not solid, the points may not be rendered.
*
* (Multi)LineStrings are translated into a sequence of a single MoveTo and
* multiple LineTo vertices, and Polygon rings into a sequence of a single
* MoveTo, multiple LineTo and a closePath command. To allow correct Polygon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ protected int parseGeometry(ValueGetter data, GeneralPath path) {
}

private void parsePoint(ValueGetter data, boolean haveZ, boolean haveM, GeneralPath path) {
path.moveTo((float) data.getDouble(), (float) data.getDouble());
path.closePath();
double x = data.getDouble();
double y = data.getDouble();
path.moveTo(x, y);
path.lineTo(x, y);
skipZM(data, haveZ, haveM);
}

Expand Down