/*
GeoJSON GeometryCollection Class
new GeometryCollection();
new GeometryCollection([geometry, geometry1]);
new GeometryCollection({
type: "GeometryCollection",
coordinates: [geometry, geometry1]
});
776460
function GeometryCollection(input){
    if(input && input.type === "GeometryCollection" && input.geometries){
      extend(this, input);
    } else if(isArray(input)) {
      this.geometries = input;
    } else if(input.coordinates && input.type){
      this.type = "GeometryCollection";
      this.geometries = [input];
    } else {
      throw "Terraformer: invalid input for Terraformer.GeometryCollection";
    }

    this.type = "GeometryCollection";
  }
493954
def prepare_geojson(geojson):
    
    # TODO CW orientation.
    geojson = deepcopy(geojson)

    if geojson["type"] == "Feature":
        geojson = geojson["geometry"]
        if hasattr(geojson, 'properties'):
            del geojson['properties']

    if geojson["type"] == "FeatureCollection":
        geojson["type"] = "GeometryCollection"
        geojson["geometries"] = [
            feature["geometry"] for feature in geojson["features"]
        ]
        del geojson["features"]

    return geojson
1280718
public function jsonSerialize()
    {
        $points = [];
        foreach ($this->points as $point) {
            $points[] = $point->jsonSerialize();
        }

        return new \GeoJson\Geometry\LineString($points);
    }
1365857
def to_topojson(self):
        """"""
        topojson = self.topojson
        topojson["objects"]["points"] = {
            "type": "GeometryCollection",
            "geometries": [point.to_topojson() for point in self.points.all()],
        }
        return json.dumps(topojson)
996162
private function readGeometryCollection(WKBBuffer $buffer, CoordinateSystem $cs) : GeometryCollection
    {
        $numGeometries = $buffer->readUnsignedLong();
        $geometries = [];

        for ($i = 0; $i < $numGeometries; $i++) {
            $geometries[] = $this->readGeometry($buffer, $cs->SRID());
        }

        return new GeometryCollection($cs, ...$geometries);
    }
617840
protected com.vividsolutions.jts.geom.Geometry toJtsGeometryCollection(Geometry<?> src) {

        com.vividsolutions.jts.geom.Geometry returnGeometry;
        if (src instanceof Point) {
            returnGeometry = toJtsPoint((Point) src);
        } else if (src instanceof LineString) {
            returnGeometry = toJtsLineString((LineString) src);
        } else if (src instanceof Polygon) {
            returnGeometry = toJtsPolygon((Polygon) src);
        } else if (src instanceof MultiPoint) {
            AbstractJtsCodec<com.vividsolutions.jts.geom.MultiPoint, MultiPoint> codec = new MultiPointCodec(this.geometryFactory);
            returnGeometry = codec.fromGeometry((MultiPoint) src);
        } else if (src instanceof MultiLineString) {
            AbstractJtsCodec<com.vividsolutions.jts.geom.MultiLineString, MultiLineString> codec = new MultiLineStringCodec(this.geometryFactory);
            returnGeometry = codec.fromGeometry((MultiLineString) src);
        } else if (src instanceof MultiPolygon) {
            AbstractJtsCodec<com.vividsolutions.jts.geom.MultiPolygon, MultiPolygon> codec = new MultiPolygonCodec(this.geometryFactory);
            returnGeometry = codec.fromGeometry((MultiPolygon) src);
        } else if (src instanceof GeometryCollection) {
            GeometryCollection geometryCollection = (GeometryCollection) src;
            returnGeometry = this.geometryFactory.createGeometryCollection(StreamSupport.stream(geometryCollection.getGeometries().spliterator(), false)
                    .map(this::toJtsGeometryCollection)
                    .toArray(com.vividsolutions.jts.geom.Geometry[]::new));
        } else {
            throw new IllegalArgumentException("Unsupported geometry type: " + src.type());
        }
        return returnGeometry;
    }
517694
function(geometry) {
            var kml = this.createElementNS(this.kmlns, "Polygon");
            var rings = geometry.components;
            var ringMember, ringGeom, type;
            for(var i=0, len=rings.length; i<len; ++i) {
                type = (i==0) ? "outerBoundaryIs" : "innerBoundaryIs";
                ringMember = this.createElementNS(this.kmlns, type);
                ringGeom = this.buildGeometry.linearring.apply(this,
                                                               [rings[i]]);
                ringMember.appendChild(ringGeom);
                kml.appendChild(ringMember);
            }
            return kml;
        }
645857
public void addGeometry(Geometry geometry) {
    if (geometry instanceof LineString) {
      addLineString(originalSegments, (LineString) geometry);
    } else if (geometry instanceof Polygon) {
      addPolygon(originalSegments, (Polygon) geometry);
    } else if (geometry instanceof GeometryCollection) {
      addGeometry(originalSegments, (GeometryCollection) geometry);
    }
  }
379591
function () {
    // Create hash table for easy reference
    var collectionValues = hashTable(this.collection.toJSON(), 'label', 'value')
    var filteredCollectionValues = hashTable(this.filteredCollection.toJSON(), 'label', 'value')

    // Add value from hash tables to geojson properties
    var idAttribute = this.boundaries.idAttribute
    var filtered = this.filteredCollection.getFilters().length
    this.boundaries.forEach(function (item) {
      var properties = item.get('properties')
      properties.value = collectionValues[properties[idAttribute]]
      if (filtered) {
        properties.filteredValue = filteredCollectionValues[properties[idAttribute]] || 0
      }
      item.set('properties', properties)
    }, this)
  }
522227
public static Geometry geomFromGeoJSON(String geojson) throws IOException, SQLException {
        if (geojson == null) {
            return null;
        }
        if (jsFactory == null) {
            jsFactory = new JsonFactory();
            jsFactory.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
            jsFactory.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
            jsFactory.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
            reader = new GJGeometryReader(new GeometryFactory());
        }
        JsonParser jp = jsFactory.createParser(geojson);
        return reader.parseGeometry(jp);
    }
745891
@Override
	protected void addCoordinateToGeometry(Coordinate newCoordinate) {
		boolean geometryHasCoordinates = geometry.getCoordinates() != null;

		// determine length and coordinates
		int length = geometryHasCoordinates ? geometry.getCoordinates().length : 0;
		Coordinate[] oldCoords = geometryHasCoordinates ? geometry.getCoordinates() : null;
		Coordinate[] newCoords = new Coordinate[length + 1];
		if (geometryHasCoordinates) {
			System.arraycopy(oldCoords, 0, newCoords, 0, length);
		}

		// put new coordinate in right position
		if (newCoords.length < 2) {
			newCoords[length] = newCoordinate;
		} else {
			newCoords[length] = newCoords[length - 1];
			newCoords[length - 1] = newCoordinate;
		}

		// create new geometry
		LinearRing linearRing = factory.createLinearRing(newCoords);
		geometry = factory.createPolygon(linearRing, null);

		// update drawing
		updateTempLineAfterClick();
	}
285945
function validateGeoJson(geoJson) {
  if (!geoJson)
    throw new Error('No geojson passed');

  if (geoJson.type !== 'FeatureCollection' &&
    geoJson.type !== 'GeometryCollection' &&
    geoJson.type !== 'MultiLineString' &&
    geoJson.type !== 'LineString' &&
    geoJson.type !== 'Feature'
  )
    throw new Error(`Invalid input type '${geoJson.type}'. Geojson must be FeatureCollection, GeometryCollection, LineString, MultiLineString or Feature`);
}
378390
function calculateBoundsForGeometryCollection(geometryCollection){
    var extents = [], extent;

    for (var i = geometryCollection.geometries.length - 1; i >= 0; i--) {
      extent = calculateBounds(geometryCollection.geometries[i]);
      extents.push([extent[0],extent[1]]);
      extents.push([extent[2],extent[3]]);
    }

    return calculateBoundsFromArray(extents);
  }
860202
function(json){
    
    // Protect against forgetting the new keyword when calling the constructor
    if(!(this instanceof Collection)){
      return new Collection(json);
    }
    
    // If the given object is already an instance then just return it. DON'T copy it.
    if(Collection.isInstance(json)){
      return json;
    }
    
    this.init(json);
  }
700963
def fromGeoJson(struct, attributes=None):
    ""
    if isinstance(struct, basestring):
        struct = json.loads(struct)
    type_map = {
        'Point': Point,
        'MultiLineString': Polyline,
        'LineString': Polyline,
        'Polygon': Polygon,
        'MultiPolygon': Polygon,
        'MultiPoint': Multipoint,
        'Box': Envelope
    }
    if struct['type'] == "Feature":
        return fromGeoJson(struct, struct.get('properties', None))
    elif struct['type'] == "FeatureCollection":
        sr = None
        if 'crs' in struct:
            sr = SpatialReference(struct['crs']['properties']['code'])
            members = map(fromGeoJson, struct['members'])
            for member in members:
                member.spatialReference = sr
            return members
        else:
            return map(fromGeoJson, struct['members'])
    elif struct['type'] in type_map and hasattr(type_map[struct['type']], 
                                              'fromGeoJson'):
        instances = type_map[struct['type']].fromGeoJson(struct)
        i = []
        assert instances is not None, "GeoJson conversion returned a Null geom"
        for instance in instances:
            if 'properties' in struct:
                instance.attributes = struct['properties'].copy()
                if '@esri.sr' in instance.attributes:
                    instance.spatialReference = SpatialReference.fromJson(
                                               instance.attributes['@esri.sr'])
                    del instance.attributes['@esri.sr']
            if attributes:
                if not hasattr(instance, 'attributes'):
                    instance.attributes = {}
                for k, v in attributes.iteritems():
                    instance.attributes[k] = v
            i.append(instance)
        if i:
            if len(i) > 1:
                return i
            return i[0]
    raise ValueError("Unconvertible to geometry")
899778
private void parseGeometryMetadata(JsonParser jp, String geometryType) throws IOException, SQLException {        
        if (geometryType.equalsIgnoreCase(GeoJsonField.POINT)) {
             parsePointMetadata(jp);
             finalGeometryTypes.add(GeoJsonField.POINT);
        } else if (geometryType.equalsIgnoreCase(GeoJsonField.MULTIPOINT)) {
             parseMultiPointMetadata(jp);
             finalGeometryTypes.add(GeoJsonField.MULTIPOINT);
        } else if (geometryType.equalsIgnoreCase(GeoJsonField.LINESTRING)) {
             parseLinestringMetadata(jp);
             finalGeometryTypes.add(GeoJsonField.LINESTRING);
        } else if (geometryType.equalsIgnoreCase(GeoJsonField.MULTILINESTRING)) {
            parseMultiLinestringMetadata(jp);
            finalGeometryTypes.add(GeoJsonField.MULTILINESTRING);
        } else if (geometryType.equalsIgnoreCase(GeoJsonField.POLYGON)) {
             parsePolygonMetadata(jp);
             finalGeometryTypes.add(GeoJsonField.POLYGON);
        } else if (geometryType.equalsIgnoreCase(GeoJsonField.MULTIPOLYGON)) {
             parseMultiPolygonMetadata(jp);
             finalGeometryTypes.add(GeoJsonField.MULTIPOLYGON);
        } else if (geometryType.equalsIgnoreCase(GeoJsonField.GEOMETRYCOLLECTION)) {
             parseGeometryCollectionMetadata(jp);
             finalGeometryTypes.add(GeoJsonField.GEOMETRYCOLLECTION);
        } else {
            throw new SQLException("Unsupported geometry : " + geometryType);
        }
    }
439416
function(geometry) {
        var node = this.createElementNS(this.namespaces.gpx, "wpt");
        node.setAttribute("lon", geometry.x);
        node.setAttribute("lat", geometry.y);
        return node;
    }