use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class ImportOp method _call.
/**
* Executes the import operation using the parameters that have been specified. Features will be
* added to the working tree, and a new working tree will be constructed. Either {@code all} or
* {@code table}, but not both, must be set prior to the import process.
*
* @return RevTree the new working tree
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected RevTree _call() {
// check preconditions and get the actual list of type names to import
final String[] typeNames = checkPreconditions();
for (int i = 0; i < typeNames.length; i++) {
try {
typeNames[i] = URLDecoder.decode(typeNames[i], Charsets.UTF_8.displayName());
} catch (UnsupportedEncodingException e) {
// shouldn't reach here.
}
}
ProgressListener progressListener = getProgressListener();
progressListener.started();
// use a local variable not to alter the command's state
boolean overwrite = this.overwrite;
if (alter) {
overwrite = false;
}
final WorkingTree workTree = workingTree();
RevFeatureType destPathFeatureType = null;
final boolean destPathProvided = destPath != null;
if (destPathProvided) {
destPathFeatureType = this.command(ResolveFeatureType.class).setRefSpec(destPath).call().orNull();
// only the last one will be imported.
if (overwrite) {
try {
workTree.delete(destPath);
} catch (Exception e) {
throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
}
overwrite = false;
}
}
int tableCount = 0;
for (String typeName : typeNames) {
{
tableCount++;
String tableName = String.format("%-16s", typeName);
if (typeName.length() > 16) {
tableName = tableName.substring(0, 13) + "...";
}
progressListener.setDescription("Importing " + tableName + " (" + tableCount + "/" + typeNames.length + ")... ");
}
FeatureSource featureSource = getFeatureSource(typeName);
SimpleFeatureType featureType = (SimpleFeatureType) featureSource.getSchema();
final String fidPrefix = featureType.getTypeName() + ".";
String path;
if (destPath == null) {
path = featureType.getTypeName();
} else {
NodeRef.checkValidPath(destPath);
path = destPath;
featureType = forceFeatureTypeName(featureType, path);
}
featureType = overrideGeometryName(featureType);
featureSource = new ForceTypeAndFidFeatureSource<FeatureType, Feature>(featureSource, featureType, fidPrefix);
boolean hasPrimaryKey = hasPrimaryKey(typeName);
boolean forbidSorting = !usePaging || !hasPrimaryKey;
((ForceTypeAndFidFeatureSource) featureSource).setForbidSorting(forbidSorting);
if (destPathFeatureType != null && adaptToDefaultFeatureType && !alter) {
featureSource = new FeatureTypeAdapterFeatureSource<FeatureType, Feature>(featureSource, destPathFeatureType.type());
}
ProgressListener taskProgress = subProgress(100.f / typeNames.length);
if (overwrite) {
try {
workTree.delete(path);
workTree.createTypeTree(path, featureType);
} catch (Exception e) {
throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
}
}
if (alter) {
// first we modify the feature type and the existing features, if needed
workTree.updateTypeTree(path, featureType);
Iterator<Feature> transformedIterator = transformFeatures(featureType, path);
try {
final Integer collectionSize = collectionSize(featureSource);
workTree.insert(path, transformedIterator, taskProgress, null, collectionSize);
} catch (Exception e) {
throw new GeoToolsOpException(StatusCode.UNABLE_TO_INSERT);
}
}
try {
insert(workTree, path, featureSource, taskProgress);
} catch (GeoToolsOpException e) {
throw e;
} catch (Exception e) {
throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
}
}
progressListener.setProgress(100.f);
progressListener.complete();
return workTree.getTree();
}
use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class DiffTreeTest method setUp.
@Before
public void setUp() throws Exception {
File workingDirectory = tempFolder.newFolder("mockWorkingDir");
Platform testPlatform = new TestPlatform(workingDirectory);
Context injector = Guice.createInjector(Modules.override(new GeogigModule()).with(new MemoryModule(testPlatform))).getInstance(Context.class);
geogit = new GeoGIG(injector);
assertNotNull(geogit.getOrCreateRepository());
diffTree = geogit.command(DiffTree.class);
SimpleFeatureType ft = DataUtilities.createType("points", "sp:String,ip:Integer,pp:Point:srid=3857");
revtype = RevFeatureTypeImpl.build(ft);
metadataId = revtype.getId();
geogit.getContext().objectDatabase().put(revtype);
}
use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class HashObjectTest method setUpInternal.
@Override
protected void setUpInternal() throws Exception {
featureType1 = RevFeatureTypeImpl.build(pointsType);
featureType2 = RevFeatureTypeImpl.build(linesType);
featureType1Duplicate = RevFeatureTypeImpl.build(pointsType);
pointFeature1 = RevFeatureBuilder.build(points1);
pointFeature2 = RevFeatureBuilder.build(points2);
pointFeature1Duplicate = RevFeatureBuilder.build(points1);
CommitBuilder b = new CommitBuilder();
b.setAuthor("groldan");
b.setAuthorEmail("groldan@boundlessgeo.com");
b.setCommitter("jdeolive");
b.setCommitterEmail("jdeolive@boundlessgeo.com");
b.setMessage("cool this works");
b.setCommitterTimestamp(1000);
b.setCommitterTimeZoneOffset(5);
ObjectId treeId = ObjectId.forString("fake tree content");
b.setTreeId(treeId);
ObjectId parentId1 = ObjectId.forString("fake parent content 1");
ObjectId parentId2 = ObjectId.forString("fake parent content 2");
List<ObjectId> parentIds = ImmutableList.of(parentId1, parentId2);
b.setParentIds(parentIds);
commit1 = b.build();
commit1Duplicate = b.build();
b.setMessage(null);
b.setAuthor(null);
b.setAuthorEmail(null);
b.setCommitterTimestamp(-1000);
b.setCommitterTimeZoneOffset(-5);
b.setParentIds(ImmutableList.of(parentId1, ObjectId.NULL));
commit2 = b.build();
Object boolArray = new boolean[] { true, false, true, true, false };
Object byteArray = new byte[] { 100, 127, -110, 26, 42 };
Object charArray = new char[] { 'a', 'b', 'c', 'd', 'e' };
Object doubleArray = new double[] { 1.5, 1.6, 1.7, 1.8 };
Object floatArray = new float[] { 1.1f, 3.14f, 6.0f, 0.0f };
Object intArray = new int[] { 5, 7, 9, 11, 32 };
Object longArray = new long[] { 100, 200, 300, 400 };
TestSerializableObject serializableObject = new TestSerializableObject();
serializableObject.words = "words to serialize";
SimpleFeatureType coverageFeatureType = DataUtilities.createType("http://geoserver.org/test", "TestType", "str:String," + "str2:String," + "bool:Boolean," + "byte:java.lang.Byte," + "doub:Double," + "bdec:java.math.BigDecimal," + "flt:Float," + "int:Integer," + "bint:java.math.BigInteger," + "boolArray:java.lang.Object," + "byteArray:java.lang.Object," + "charArray:java.lang.Object," + "doubleArray:java.lang.Object," + "floatArray:java.lang.Object," + "intArray:java.lang.Object," + "longArray:java.lang.Object," + "serialized:java.io.Serializable," + "randomClass:java.lang.Object," + "pp:Point:srid=4326," + "lng:java.lang.Long," + "uuid:java.util.UUID");
coverageRevFeatureType = RevFeatureTypeImpl.build(coverageFeatureType);
Feature coverageFeature = feature(coverageFeatureType, "TestType.Coverage.1", "StringProp1_1", null, Boolean.TRUE, Byte.valueOf("18"), new Double(100.01), new BigDecimal("1.89e1021"), new Float(12.5), new Integer(1000), new BigInteger("90000000"), boolArray, byteArray, charArray, doubleArray, floatArray, intArray, longArray, serializableObject, new SomeRandomClass(), "POINT(1 1)", new Long(800000), UUID.fromString("bd882d24-0fe9-11e1-a736-03b3c0d0d06d"));
coverageRevFeature = RevFeatureBuilder.build(coverageFeature);
hashCommand = new HashObject();
Context mockCommandLocator = mock(Context.class);
hashCommand.setContext(mockCommandLocator);
when(mockCommandLocator.command(eq(DescribeFeatureType.class))).thenReturn(new DescribeFeatureType());
}
use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class MappingTest method TestLoadingFromFile.
@Test
public void TestLoadingFromFile() {
String mappingFilename = OSMMap.class.getResource("mapping.json").getFile();
File mappingFile = new File(mappingFilename);
Mapping mapping = Mapping.fromFile(mappingFile.getAbsolutePath());
List<MappingRule> rules = mapping.getRules();
assertEquals(1, rules.size());
MappingRule rule = rules.get(0);
SimpleFeatureType ft = rule.getFeatureType();
assertEquals("id", ft.getDescriptor(0).getLocalName());
assertEquals("lit", ft.getDescriptor(1).getLocalName());
assertEquals("geom", ft.getDescriptor(2).getLocalName());
assertEquals("nodes", ft.getDescriptor(3).getLocalName());
}
use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class FormatCommonV1 method readFeatureType.
public static RevFeatureType readFeatureType(ObjectId id, DataInput in, FeatureTypeFactory typeFactory) throws IOException {
Name name = readName(in);
int propertyCount = in.readInt();
List<AttributeDescriptor> attributes = new ArrayList<AttributeDescriptor>();
for (int i = 0; i < propertyCount; i++) {
attributes.add(readAttributeDescriptor(in, typeFactory));
}
SimpleFeatureType ftype = typeFactory.createSimpleFeatureType(name, attributes, null, false, Collections.<Filter>emptyList(), BasicFeatureTypes.FEATURE, null);
return new RevFeatureTypeImpl(id, ftype);
}
Aggregations