Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.baremaps.geoparquet;
import java.util.ArrayList;
import java.util.List;
import org.apache.baremaps.geoparquet.GeoParquetSchema.EnvelopeField;
import org.apache.baremaps.geoparquet.GeoParquetSchema.Field;
import org.apache.baremaps.geoparquet.GeoParquetSchema.GroupField;
import org.apache.baremaps.geoparquet.GeoParquetSchema.Type;
import org.apache.parquet.io.api.Binary;
import org.apache.parquet.schema.GroupType;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKBReader;
import org.locationtech.jts.io.WKBWriter;
/**
* A group of fields in a GeoParquet file.
*/
public class GeoParquetGroup {
private final GroupType parquetSchema;
private final GeoParquetMetadata geoParquetMetadata;
private final GeoParquetSchema geoParquetSchema;
private final Object[] data;
/**
* Constructs a new GeoParquetGroup with the specified schema, metadata and GeoParquet schema.
*
* @param parquetSchema
* @param geoParquetMetadata
* @param geoParquetSchema
*/
public GeoParquetGroup(GroupType parquetSchema, GeoParquetMetadata geoParquetMetadata,
GeoParquetSchema geoParquetSchema) {
this.parquetSchema = parquetSchema;
this.geoParquetMetadata = geoParquetMetadata;
this.geoParquetSchema = geoParquetSchema;
this.data = new Object[parquetSchema.getFields().size()];
for (int i = 0; i < parquetSchema.getFieldCount(); i++) {
Field field = geoParquetSchema.fields().get(i);
if (field.cardinality() == GeoParquetSchema.Cardinality.REPEATED) {
this.data[i] = new ArrayList<>();
} else {
this.data[i] = null; // For REQUIRED or OPTIONAL fields
}
}
}
public GeoParquetGroup addGroup(int fieldIndex) {
GeoParquetGroup group = createGroup(fieldIndex);
add(fieldIndex, group);
return group;
}
public GeoParquetGroup addGroup(String field) {
return addGroup(getParquetSchema().getFieldIndex(field));
}
private GeoParquetGroup createGroup(int fieldIndex) {
Field field = geoParquetSchema.fields().get(fieldIndex);
if (field instanceof EnvelopeField envelopeField) {
return new GeoParquetGroup(parquetSchema.getType(fieldIndex).asGroupType(),
geoParquetMetadata,
envelopeField.schema());
} else if (field instanceof GroupField groupField) {
return new GeoParquetGroup(parquetSchema.getType(fieldIndex).asGroupType(),
geoParquetMetadata,
groupField.schema());
}
throw new GeoParquetException("Field at index " + fieldIndex + " is not a group");
}
public GeoParquetGroup getGroup(int fieldIndex, int index) {
return (GeoParquetGroup) getValue(fieldIndex, index);
}
public GeoParquetGroup getGroup(String field, int index) {
return getGroup(getParquetSchema().getFieldIndex(field), index);
}
public int getFieldRepetitionCount(int fieldIndex) {
Object value = data[fieldIndex];
if (value instanceof List>list) {
return list.size();
} else {
return value == null ? 0 : 1;
}
}
Object getValue(int fieldIndex, int index) {
Object value = data[fieldIndex];
if (value instanceof List>list) {
return list.get(index);
} else if (index == 0) {
return value;
} else {
throw createGeoParquetException(fieldIndex, "element number " + index);
}
}
private Object getValue(int fieldIndex) {
Field field = geoParquetSchema.fields().get(fieldIndex);
if (field.cardinality() == GeoParquetSchema.Cardinality.REPEATED) {
throw new IllegalStateException("Field " + fieldIndex + " (" + field.name()
+ ") is repeated. Use getValues() instead.");
}
return data[fieldIndex];
}
public List