Reproject a set of geometries

@param from       the starting crs
@param to         the destination crs
@param geometries the array of geometries, wrapped into an Object array

@throws Exception
355732
public static void reproject( CoordinateReferenceSystem from, CoordinateReferenceSystem to, Object[] geometries )
            throws Exception {
        MathTransform mathTransform = CRS.findMathTransform(from, to);

        for( int i = 0; i < geometries.length; i++ ) {
            geometries[i] = JTS.transform((Geometry) geometries[i], mathTransform);
        }
    }
1358962
private static void recursiveSetSrid(Geometry geometry, int srid) {
		if (geometry != null) {
			geometry.setSrid(srid);
		}
		if (geometry.getGeometries() != null) {
			for (Geometry childGeometry : geometry.getGeometries()) {
				recursiveSetSrid(childGeometry, srid);
			}
		}
	}
1238943
public static void dumpLasFolderOverview( String folder, CoordinateReferenceSystem crs ) throws Exception {
        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("overview");
        b.setCRS(crs);
        b.add("the_geom", Polygon.class);
        b.add("name", String.class);
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();

        OmsFileIterator iter = new OmsFileIterator();
        iter.inFolder = folder;
        iter.fileFilter = new FileFilter(){
            public boolean accept( File pathname ) {
                return pathname.getName().endsWith(".las");
            }
        };
        iter.process();

        List<File> filesList = iter.filesList;

        for( File file : filesList ) {
            try (ALasReader r = new LasReaderBuffered(file, crs)) {
                r.open();
                ReferencedEnvelope3D envelope = r.getHeader().getDataEnvelope();
                Polygon polygon = GeometryUtilities.createPolygonFromEnvelope(envelope);
                Object[] objs = new Object[]{polygon, r.getLasFile().getName()};
                builder.addAll(objs);
                SimpleFeature feature = builder.buildFeature(null);
                newCollection.add(feature);
            }
        }

        File folderFile = new File(folder);
        File outFile = new File(folder, "overview_" + folderFile.getName() + ".shp");
        OmsVectorWriter.writeVector(outFile.getAbsolutePath(), newCollection);
    }
566991
public static JoinPoint<Exception> fromSynchronizationPoints(Collection<? extends ISynchronizationPoint<?>> synchPoints) {
		JoinPoint<Exception> jp = new JoinPoint<>();
		for (ISynchronizationPoint<?> sp : synchPoints)
			jp.addToJoin(sp);
		jp.start();
		return jp;
	}
1042253
@Override
	public void move(List<GeometryIndex> indices, List<List<Coordinate>> coordinates)
			throws GeometryOperationFailedException {
		if (indices == null || coordinates == null || indices.size() == 0 || coordinates.size() == 0) {
			throw new GeometryOperationFailedException("Illegal arguments passed; nothing to move.");
		}

		Geometry geometry = service.getGeometry();
		OperationSequence seq = null;
		if (isOperationSequenceActive()) {
			seq = current;
		} else {
			seq = new OperationSequence();
			redoQueue.clear();
		}
		for (int i = 0; i < indices.size(); i++) {
			if (indexService.getType(indices.get(i)) == GeometryIndexType.TYPE_VERTEX) {
				GeometryIndexOperation op = new MoveVertexOperation(indexService, coordinates.get(i).get(0));
				executeOperation(op, indices.get(i));
				seq.addOperation(op);
			} else {
				throw new GeometryOperationFailedException("Can only move vertices. Other types not suported.");
			}
		}
		if (!isOperationSequenceActive()) {
			undoQueue.add(seq);
		}
		eventBus.fireEvent(new GeometryEditMoveEvent(geometry, indices));
		if (!isOperationSequenceActive()) {
			eventBus.fireEvent(new GeometryEditShapeChangedEvent(service.getGeometry()));
		}
	}
313652
@SuppressWarnings("unchecked")
    public GoogleMapShape toShape(Geometry geometry) {

        GoogleMapShape shape = null;

        GeometryType geometryType = geometry.getGeometryType();
        switch (geometryType) {
            case POINT:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.LAT_LNG, toLatLng((Point) geometry));
                break;
            case LINESTRING:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.POLYLINE_OPTIONS,
                        toPolyline((LineString) geometry));
                break;
            case POLYGON:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.POLYGON_OPTIONS,
                        toPolygon((Polygon) geometry));
                break;
            case MULTIPOINT:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_LAT_LNG,
                        toLatLngs((MultiPoint) geometry));
                break;
            case MULTILINESTRING:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_POLYLINE_OPTIONS,
                        toPolylines((MultiLineString) geometry));
                break;
            case MULTIPOLYGON:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_POLYGON_OPTIONS,
                        toPolygons((MultiPolygon) geometry));
                break;
            case CIRCULARSTRING:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.POLYLINE_OPTIONS,
                        toPolyline((CircularString) geometry));
                break;
            case COMPOUNDCURVE:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_POLYLINE_OPTIONS,
                        toPolylines((CompoundCurve) geometry));
                break;
            case CURVEPOLYGON:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.POLYGON_OPTIONS,
                        toCurvePolygon((CurvePolygon) geometry));
                break;
            case POLYHEDRALSURFACE:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_POLYGON_OPTIONS,
                        toPolygons((PolyhedralSurface) geometry));
                break;
            case TIN:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.MULTI_POLYGON_OPTIONS,
                        toPolygons((TIN) geometry));
                break;
            case TRIANGLE:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.POLYGON_OPTIONS,
                        toPolygon((Triangle) geometry));
                break;
            case GEOMETRYCOLLECTION:
                shape = new GoogleMapShape(geometryType,
                        GoogleMapShapeType.COLLECTION,
                        toShapes((GeometryCollection<Geometry>) geometry));
                break;
            default:
                throw new GeoPackageException("Unsupported Geometry Type: "
                        + geometryType.getName());
        }

        return shape;
    }
542293
@PostConstruct
	protected void postConstruct() throws GeomajasException {
		if (null != crsDefinitions) {
			for (CrsInfo crsInfo : crsDefinitions.values()) {
				try {
					CoordinateReferenceSystem crs = CRS.parseWKT(crsInfo.getCrsWkt());
					String code = crsInfo.getKey();
					crsCache.put(code, CrsFactory.getCrs(code, crs));
				} catch (FactoryException e) {
					throw new GeomajasException(e, ExceptionCode.CRS_DECODE_FAILURE_FOR_MAP, crsInfo.getKey());
				}
			}
		}
		if (null != crsTransformDefinitions) {
			for (CrsTransformInfo crsTransformInfo : crsTransformDefinitions.values()) {
				String key = getTransformKey(crsTransformInfo);
				transformCache.put(key, getCrsTransform(key, crsTransformInfo));
			}
		}
		GeometryFactory factory = new GeometryFactory();
		EMPTY_GEOMETRIES.put(Point.class, factory.createPoint((Coordinate) null));
		EMPTY_GEOMETRIES.put(LineString.class, factory.createLineString((Coordinate[]) null));
		EMPTY_GEOMETRIES.put(Polygon.class, factory.createPolygon(null, null));
		EMPTY_GEOMETRIES.put(MultiPoint.class, factory.createMultiPoint((Coordinate[]) null));
		EMPTY_GEOMETRIES.put(MultiLineString.class, factory.createMultiLineString((LineString[]) null)); // cast needed!
		EMPTY_GEOMETRIES.put(MultiPolygon.class, factory.createMultiPolygon((Polygon[]) null)); // cast needed!
		EMPTY_GEOMETRIES.put(Geometry.class, factory.createGeometryCollection(null));
	}
586925
public static com.vividsolutions.jts.geom.Coordinate toJts(org.geomajas.geometry.Coordinate coordinate)
			throws JtsConversionException {
		if (coordinate == null) {
			throw new  JtsConversionException("Cannot convert null argument");
		}
		return new com.vividsolutions.jts.geom.Coordinate(coordinate.getX(), coordinate.getY());
	}
1278709
@ExportInstanceMethod
	public static void setShape(PointSymbolizerShapeAndSize instance, String shape) {
		if ("circle".equals(shape)) {
			instance.setShape(PointSymbolizerShapeAndSize.Shape.CIRCLE);
		} else if ("square".equals(shape)) {
			instance.setShape(PointSymbolizerShapeAndSize.Shape.SQUARE);
		} else {
			//default value
			instance.setShape(PointSymbolizerShapeAndSize.Shape.SQUARE);
		}
	}
557924
public void setDimensions(java.util.Collection<SegmentDimensions> dimensions) {
        if (dimensions == null) {
            this.dimensions = null;
            return;
        }

        this.dimensions = new java.util.ArrayList<SegmentDimensions>(dimensions);
    }
690719
public static Vector<Object> toXmlRpcProjectsParameters(Collection<Project> projects)
    { 
        Vector<Object> projectsParams = new Vector<Object>();        
        for(Project project : projects)
        {
            projectsParams.add(project.marshallize());
        }
        
        return projectsParams;
    }
849040
private void buildMappings(final CronDefinition from, final CronDefinition to) {
        final Map<CronFieldName, FieldDefinition> sourceFieldDefinitions = getFieldDefinitions(from);
        final Map<CronFieldName, FieldDefinition> destFieldDefinitions = getFieldDefinitions(to);
        boolean startedDestMapping = false;
        boolean startedSourceMapping = false;
        for (final CronFieldName name : CronFieldName.values()) {
            final FieldDefinition destinationFieldDefinition = destFieldDefinitions.get(name);
            final FieldDefinition sourceFieldDefinition = sourceFieldDefinitions.get(name);
            if (destinationFieldDefinition != null) {
                startedDestMapping = true;
            }
            if (sourceFieldDefinition != null) {
                startedSourceMapping = true;
            }
            if (startedDestMapping && destinationFieldDefinition == null) {
                break;
            }
            //destination has fields before source definition starts. We default them to zero.
            if (!startedSourceMapping && destinationFieldDefinition != null) {
                mappings.put(name, returnOnZeroExpression(name));
            }
            //destination has fields after source definition was processed. We default them to always.
            if (startedSourceMapping && sourceFieldDefinition == null && destinationFieldDefinition != null) {
                mappings.put(name, returnAlwaysExpression(name));
            }
            if (sourceFieldDefinition == null || destinationFieldDefinition == null) {
                continue;
            }
            if (CronFieldName.DAY_OF_WEEK.equals(name)) {
                mappings.put(name, dayOfWeekMapping((DayOfWeekFieldDefinition) sourceFieldDefinition, (DayOfWeekFieldDefinition) destinationFieldDefinition));
            } else if (CronFieldName.DAY_OF_MONTH.equals(name)) {
                mappings.put(name, dayOfMonthMapping(sourceFieldDefinition, destinationFieldDefinition));
            } else {
                mappings.put(name, returnSameExpression());
            }
        }
    }
173069
private Collection<Geometry> restoreDim4(Collection<Geometry> geoms, Map<Coordinate, Double> map) {
        GeometryFactory factory = new GeometryFactory(
                new PackedCoordinateSequenceFactory(PackedCoordinateSequenceFactory.DOUBLE, 4));
        Collection<Geometry> result = new ArrayList<>();
        for (Geometry geom : geoms) {
            if (geom instanceof Point) {
                result.add(factory.createPoint(restoreDim4(
                        ((Point) geom).getCoordinateSequence(), map)));
            } else if (geom instanceof LineString) {
                result.add(factory.createLineString(restoreDim4(
                        ((LineString) geom).getCoordinateSequence(), map)));
            } else if (geom instanceof Polygon) {
                LinearRing outer = factory.createLinearRing(restoreDim4(
                        ((Polygon) geom).getExteriorRing().getCoordinateSequence(), map));
                LinearRing[] inner = new LinearRing[((Polygon) geom).getNumInteriorRing()];
                for (int i = 0; i < ((Polygon) geom).getNumInteriorRing(); i++) {
                    inner[i] = factory.createLinearRing(restoreDim4(
                            ((Polygon) geom).getInteriorRingN(i).getCoordinateSequence(), map));
                }
                result.add(factory.createPolygon(outer, inner));
            } else {
                for (int i = 0; i < geom.getNumGeometries(); i++) {
                    result.addAll(restoreDim4(Collections.singleton(geom.getGeometryN(i)), map));
                }
            }
        }
        return result;
    }
1216270
function(geometry) {
        if (this.internalProjection && this.externalProjection) {
            geometry = geometry.clone();
            geometry.transform(this.internalProjection, 
                               this.externalProjection);
        }
        var node;
        // match Polygon
        if (geometry.CLASS_NAME == "OpenLayers.Geometry.Polygon") {
            node = this.createElementNS(this.georssns, 'georss:polygon');
            
            node.appendChild(this.buildCoordinatesNode(geometry.components[0]));
        }
        // match LineString
        else if (geometry.CLASS_NAME == "OpenLayers.Geometry.LineString") {
            node = this.createElementNS(this.georssns, 'georss:line');
            
            node.appendChild(this.buildCoordinatesNode(geometry));
        }
        // match Point
        else if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
            node = this.createElementNS(this.georssns, 'georss:point');
            node.appendChild(this.buildCoordinatesNode(geometry));
        } else {
            throw "Couldn't parse " + geometry.CLASS_NAME;
        }  
        return node;         
    }
1208046
private static Geometry[] convertGeometries(org.geomajas.gwt.client.spatial.geometry.Geometry geometry) {
		if (geometry.isEmpty()) {
			return null;
		}
		Geometry[] geometries = new Geometry[geometry.getNumGeometries()];
		for (int i = 0; i < geometries.length; i++) {
			geometries[i] = toDto(geometry.getGeometryN(i));
		}
		return geometries;
	}
462281
def reproject(self, projection):
        
        srs_out = crsConvert(projection, 'osr')
        
        if self.srs.IsSame(srs_out) == 0:
            
            # create the CoordinateTransformation
            coordTrans = osr.CoordinateTransformation(self.srs, srs_out)
            
            layername = self.layername
            geomType = self.geomType
            features = self.getfeatures()
            feat_def = features[0].GetDefnRef()
            fields = [feat_def.GetFieldDefn(x) for x in range(0, feat_def.GetFieldCount())]
            
            self.__init__()
            self.addlayer(layername, srs_out, geomType)
            self.layer.CreateFields(fields)
            
            for feature in features:
                geom = feature.GetGeometryRef()
                geom.Transform(coordTrans)
                newfeature = feature.Clone()
                newfeature.SetGeometry(geom)
                self.layer.CreateFeature(newfeature)
                newfeature = None
            self.init_features()
1339440
@Override
	public double execute(Geometry geom1, Geometry geom2,
			ProgressTracker progressTracker) {
		if (null == geom1 || null == geom2) {
			throw new IllegalArgumentException();
		}

		Geometry geometryA = geom1;
		Geometry geometryB = geom2;

		if (geometryA.isEmpty() || geometryB.isEmpty())
			return NumberUtils.TheNaN;		

		Polygon polygonA;
		Polygon polygonB;
		MultiPoint multiPointA;
		MultiPoint multiPointB;

		// if geometryA is an envelope use a polygon instead (if geom1 was
		// folded, then geometryA will already be a polygon)
		// if geometryA is a point use a multipoint instead
		Geometry.Type gtA = geometryA.getType();
		Geometry.Type gtB = geometryB.getType();
		if (gtA == Geometry.Type.Point) {
			if (gtB == Geometry.Type.Point) {
				return Point2D.distance(((Point)geometryA).getXY(), ((Point)geometryB).getXY());
			}
			else if (gtB == Geometry.Type.Envelope) {
				Envelope2D envB = new Envelope2D();
				geometryB.queryEnvelope2D(envB);
				return envB.distance(((Point)geometryA).getXY());
			}
			
			multiPointA = new MultiPoint();
			multiPointA.add((Point) geometryA);
			geometryA = multiPointA;
		} else if (gtA == Geometry.Type.Envelope) {
			if (gtB == Geometry.Type.Envelope) {
				Envelope2D envA = new Envelope2D();
				geometryA.queryEnvelope2D(envA);
				Envelope2D envB = new Envelope2D();
				geometryB.queryEnvelope2D(envB);
				return envB.distance(envA);
			}
			polygonA = new Polygon();
			polygonA.addEnvelope((Envelope) geometryA, false);
			geometryA = polygonA;
		}

		// if geom_2 is an envelope use a polygon instead
		// if geom_2 is a point use a multipoint instead
		if (gtB == Geometry.Type.Point) {
			multiPointB = new MultiPoint();
			multiPointB.add((Point) geometryB);
			geometryB = multiPointB;
		} else if (gtB == Geometry.Type.Envelope) {
			polygonB = new Polygon();
			polygonB.addEnvelope((Envelope) geometryB, false);
			geometryB = polygonB;
		}

		DistanceCalculator distanceCalculator = new DistanceCalculator(
				progressTracker);
		double distance = distanceCalculator.calculate(geometryA, geometryB);
		return distance;
	}