📄 polygongeometry.java
字号:
} } public static class XY extends PolygonGeometry { /** The array of x pixel coordinates. */ protected int[] xs = null; /** The array of y pixel coordinates. */ protected int[] ys = null; /** * To satify the Offset constructor complaint. */ protected XY() {} /** * Create an OMPoly from a list of xy pairs. If you want the * poly to be connected, you need to ensure that the first and * last coordinate pairs are the same. * * @param xypoints array of x/y points, arranged x, y, x, y, * etc. */ public XY(int[] xypoints) { setLocation(xypoints); } /** * Create an x/y OMPoly. If you want the poly to be connected, * you need to ensure that the first and last coordinate pairs * are the same. * * @param xPoints int[] of x coordinates * @param yPoints int[] of y coordinates */ public XY(int[] xPoints, int[] yPoints) { setLocation(xPoints, yPoints); } /** * Set an OMPoly from a list of xy pixel pairs. If you want * the poly to be connected, you need to ensure that the first * and last coordinate pairs are the same. This is for * RENDERTYPE_XY polys. * * @param xypoints array of x/y points, arranged x, y, x, y, * etc. */ public void setLocation(int[] xypoints) { int end = xypoints.length >> 1; xs = new int[end]; ys = new int[end]; for (int i = 0, j = 0; i < end; i++, j += 2) { xs[i] = xypoints[j]; ys[i] = xypoints[j + 1]; } setNeedToRegenerate(true); } /** * Set an OMPoly from a x/y coordinates. If you want the poly * to be connected, you need to ensure that the first and last * coordinate pairs are the same. This is for RENDERTYPE_XY * polys. * * @param xPoints int[] of x coordinates * @param yPoints int[] of y coordinates */ public void setLocation(int[] xPoints, int[] yPoints) { xs = xPoints; ys = yPoints; setNeedToRegenerate(true); } /** * Set the array of x points. */ public void setXs(int[] x) { xs = x; setNeedToRegenerate(true); } /** * Get the array of x points. */ public int[] getXs() { return xs; } /** * Set the array of y points. */ public void setYs(int[] y) { ys = y; setNeedToRegenerate(true); } /** * Get the array of y points. */ public int[] getYs() { return ys; } public boolean generate(Projection proj) { shape = null; if (proj == null) { Debug.message("omgraphic", "OMPoly: null projection in generate!"); return false; } if (xs == null) { Debug.message("omgraphic", "OMPoly x/y rendertype null coordinates"); return false; } // Need to keep these around for the LabeledOMPoly xpoints = new int[1][0]; xpoints[0] = xs; ypoints = new int[1][0]; ypoints[0] = ys; if (doShapes) { createShape(); } setNeedToRegenerate(false); return true; } protected void createShape() { if (getNeedToRegenerate()) { return; } shape = BasicGeometry.createShape(xpoints[0], ypoints[0], isPolygon); } public int getRenderType() { return RENDERTYPE_XY; } } public static class Offset extends XY { /** * Translation offsets. The xy points are relative to the * position of fixed latlon point. */ public final static int COORDMODE_ORIGIN = 0; /** * Delta offsets. Each xy point in the array is relative to * the previous point, and the first point is relative to the * fixed latlon point. */ public final static int COORDMODE_PREVIOUS = 1; /** * The latitude of the starting point of the poly. Stored as * radians! */ protected float lat = 0.0f; /** * The longitude of the starting point of the poly. Stored as * radians! */ protected float lon = 0.0f; /** * Type of offset. * * @see #COORDMODE_ORIGIN * @see #COORDMODE_PREVIOUS */ protected int coordMode = COORDMODE_ORIGIN; /** * Create an x/y OMPoly at an offset from lat/lon. If you want * the poly to be connected, you need to ensure that the first * and last coordinate pairs are the same. * * @param latPoint latitude in decimal degrees * @param lonPoint longitude in decimal degrees * @param xypoints int[] of x,y pairs * @param cMode offset coordinate mode */ public Offset(float latPoint, float lonPoint, int[] xypoints, int cMode) { setLocation(latPoint, lonPoint, OMGraphic.DECIMAL_DEGREES, xypoints); setCoordMode(cMode); } /** * Create an x/y OMPoly at an offset from lat/lon. If you want * the poly to be connected, you need to ensure that the first * and last coordinate pairs are the same. * * @param latPoint latitude in decimal degrees * @param lonPoint longitude in decimal degrees * @param xPoints int[] of x coordinates * @param yPoints int[] of y coordinates * @param cMode offset coordinate mode */ public Offset(float latPoint, float lonPoint, int[] xPoints, int[] yPoints, int cMode) { setLocation(latPoint, lonPoint, OMGraphic.DECIMAL_DEGREES, xPoints, yPoints); setCoordMode(cMode); } /** * Set the location based on a latitude, longitude, and some * xy points. The coordinate mode and the polygon setting are * the same as in the constructor used. * * @param latPoint latitude in decimal degrees. * @param lonPoint longitude in decimal degrees. * @param units radians or decimal degrees. Use * OMGraphic.RADIANS or OMGraphic.DECIMAL_DEGREES * @param xypoints array of x/y points, arranged x, y, x, y, * etc. */ public void setLocation(float latPoint, float lonPoint, int units, int[] xypoints) { if (units == OMGraphic.DECIMAL_DEGREES) { lat = ProjMath.degToRad(latPoint); lon = ProjMath.degToRad(lonPoint); } else { lat = latPoint; lon = lonPoint; } int end = xypoints.length >> 1; xs = new int[end]; ys = new int[end]; for (int i = 0, j = 0; i < end; i++, j += 2) { xs[i] = xypoints[j]; ys[i] = xypoints[j + 1]; } setNeedToRegenerate(true); } /** * Set the location based on a latitude, longitude, and some * xy points. The coordinate mode and the polygon setting are * the same as in the constructor used. * * @param latPoint latitude in decimal degrees * @param lonPoint longitude in decimal degrees * @param units radians or decimal degrees. Use * OMGraphic.RADIANS or OMGraphic.DECIMAL_DEGREES * @param xPoints int[] of x coordinates * @param yPoints int[] of y coordinates */ public void setLocation(float latPoint, float lonPoint, int units, int[] xPoints, int[] yPoints) { if (units == OMGraphic.DECIMAL_DEGREES) { lat = ProjMath.degToRad(latPoint); lon = ProjMath.degToRad(lonPoint); } else { lat = latPoint; lon = lonPoint; } xs = xPoints; ys = yPoints; setNeedToRegenerate(true); } /** * Type of offset. * * @see #COORDMODE_ORIGIN * @see #COORDMODE_PREVIOUS */ public void setCoordMode(int coordMode) { this.coordMode = coordMode; } /** * Type of offset. * * @see #COORDMODE_ORIGIN * @see #COORDMODE_PREVIOUS */ public int getCoordMode() { return coordMode; } /** * Set the latitude of the offset point, in decimal degrees. */ public void setLat(float lat) { this.lat = ProjMath.degToRad(lat); setNeedToRegenerate(true); } /** * Get the latitude of the offset point, in decimal degrees. */ public float getLat() { return ProjMath.radToDeg(lat); } /** * Set the longitude of the offset point, in decimal degrees. */ public void setLon(float lon) { this.lon = ProjMath.degToRad(lon); setNeedToRegenerate(true); } /** * Get the longitude of the offset point, in decimal degrees. */ public float getLon() { return ProjMath.radToDeg(lon); } public boolean generate(Projection proj) { int i, npts; shape = null; if (proj == null) { Debug.message("omgraphic", "OMPoly: null projection in generate!"); return false; } if (xs == null) { Debug.message("omgraphic", "OMPoly offset rendertype null coordinates"); return false; } npts = xs.length; int[] _x = new int[npts]; int[] _y = new int[npts]; // forward project the radian point Point origin = proj.forward(lat, lon, new Point(0, 0), true);//radians if (coordMode == COORDMODE_ORIGIN) { for (i = 0; i < npts; i++) { _x[i] = xs[i] + origin.x; _y[i] = ys[i] + origin.y; } } else { // CModePrevious offset deltas _x[0] = xs[0] + origin.x; _y[0] = ys[0] + origin.y; for (i = 1; i < npts; i++) { _x[i] = xs[i] + _x[i - 1]; _y[i] = ys[i] + _y[i - 1]; } } // Need to keep these around for the LabeledOMPoly xpoints = new int[1][0]; xpoints[0] = _x; ypoints = new int[1][0]; ypoints[0] = _y; if (doShapes) { this.createShape(); } setNeedToRegenerate(false); return true; } public int getRenderType() { return RENDERTYPE_OFFSET; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -