Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
6 changes: 2 additions & 4 deletions geoportal_1/src/main/java/org/opengeoportal/download/DownloadHandlerImpl.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ SolrRecord findRecord(String layerId, List<SolrRecord> recordList) throws Except
return sr;
}
}

throw new Exception("Record not found.");
};

Expand Down Expand Up @@ -178,9 +178,7 @@ private LayerRequest createLayerRequest(SolrRecord solrRecord, String requestedF
layer.setRequestedBounds(bounds);
layer.setEmailAddress(emailAddress);
layer.setTargetDirectory(this.directoryRetriever.getDownloadDirectory());
if (LocationFieldUtils.hasWmsUrl(solrRecord.getLocation())){
addOwsInfo(layer);
}
addOwsInfo(layer);
return layer;
}

Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
6 changes: 3 additions & 3 deletions geoportal_1/src/main/java/org/opengeoportal/download/methods/AbstractDownloadMethod.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.opengeoportal.layer.BoundingBox;
import org.opengeoportal.solr.SolrRecord;
import org.opengeoportal.utilities.DirectoryRetriever;
import org.opengeoportal.utilities.LocationFieldUtils;
import org.opengeoportal.utilities.OgpFileUtils;
import org.opengeoportal.utilities.http.HttpRequester;
import org.slf4j.Logger;
Expand Down Expand Up @@ -180,10 +181,9 @@ public BoundingBox getClipBounds() throws Exception{

public Boolean hasRequiredInfo(LayerRequest layerRequest){
try {
if (getUrls(layerRequest) != null && !getUrls(layerRequest).isEmpty()){
if (getUrls(layerRequest) != null && !getUrls(layerRequest).isEmpty())
return true;
}

return false;
} catch (Exception e){
logger.debug(e.getMessage());
}
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
3 changes: 2 additions & 1 deletion geoportal_1/src/main/java/org/opengeoportal/download/methods/FeatureSourceToShape.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.opengeoportal.download.methods;

import java.io.File;
import java.util.Set;

import com.vividsolutions.jts.geom.Envelope;

public interface FeatureSourceToShape {

File exportToShapefile() throws Exception;
Set<File> exportToShapefiles() throws Exception;

void setFeatureCollectionBBox(Envelope bbox) throws Exception;

Expand Down
46 changes: 31 additions & 15 deletions geoportal_1/src/main/java/org/opengeoportal/download/methods/FeatureSourceToShapeImpl.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;

import org.geotools.data.DataStore;
import org.geotools.data.DataUtilities;
Expand All @@ -32,6 +34,7 @@
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengeoportal.utilities.DirectoryRetriever;
import org.opengeoportal.utilities.OgpFileUtils;
import org.opengeoportal.utilities.ZipFilePackager;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.FilterFactory;
Expand Down Expand Up @@ -108,23 +111,26 @@ public void setFeatureCollectionBBox(Envelope bbox) throws Exception{
* @param targetFeatureStore
* @throws IOException
*/
protected void copyFeatures(SimpleFeatureSource featureSource, SimpleFeatureStore targetStore) throws IOException{
protected void copyFeatures(SimpleFeatureSource featureSource, SimpleFeatureSource targetSource) throws IOException{

/*
* Write the features to the shapefile
*/
Transaction transaction = new DefaultTransaction();
Transaction transaction = new DefaultTransaction("create");

//if (featureSource instanceof SimpleFeatureStore) {
if (targetSource instanceof SimpleFeatureStore) {

/*
* SimpleFeatureStore has a method to add features from a
* SimpleFeatureCollection object, so we use the ListFeatureCollection
* class to wrap our list of features.
*/
SimpleFeatureStore targetStore = (SimpleFeatureStore) targetSource;
targetStore.setTransaction(transaction);

try {
SimpleFeatureCollection collection = featureSource.getFeatures();
SimpleFeatureIterator collIter = collection.features();
//SimpleFeatureIterator collIter = collection.features();

logger.info(collection.getSchema().toString());
logger.info(targetStore.getSchema().toString());
Expand All @@ -142,7 +148,10 @@ protected void copyFeatures(SimpleFeatureSource featureSource, SimpleFeatureStor
} finally {
transaction.close();
}

} else {
System.out.println(" does not support read/write access");
System.exit(1);
}
}

/**
Expand All @@ -152,9 +161,7 @@ protected void copyFeatures(SimpleFeatureSource featureSource, SimpleFeatureStor
* @throws Exception
*/
@Override
public
File exportToShapefile()
throws Exception {
public Set<File> exportToShapefiles() throws Exception {

File directory = directoryRetriever.getDownloadDirectory();

Expand All @@ -164,8 +171,8 @@ File exportToShapefile()
String typeName = ft.getTypeName();
String fileName = OgpFileUtils.filterName(typeName);

File file = new File(directory, fileName + ".shp");
file.createNewFile();
File fileSHP = new File(directory, fileName + ".shp");
fileSHP.createNewFile();

/*
* Get an output file name and create the new shapefile
Expand All @@ -174,7 +181,7 @@ File exportToShapefile()
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();

Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("url", file.toURI().toURL());
params.put("url", fileSHP.toURI().toURL());
params.put("create spatial index", Boolean.TRUE);

ShapefileDataStore shpDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
Expand All @@ -186,14 +193,23 @@ File exportToShapefile()
*/
// newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
String[] typeNames = shpDataStore.getTypeNames();
SimpleFeatureStore featureStore = (SimpleFeatureStore) shpDataStore.getFeatureSource(typeNames[0]);
SimpleFeatureSource shpFeatureSource =shpDataStore.getFeatureSource(typeNames[0]);

logger.info("created schema");

logger.info("created feature store");
copyFeatures(featureSource, featureStore);
copyFeatures(featureSource, shpFeatureSource);
logger.info("copied features");

Set<File> shapeFileSet = new HashSet<File>();
File fileDBF = new File(directory, fileName + ".dbf");
File fileSHX = new File(directory, fileName + ".shx");
File filePRJ = new File(directory, fileName + ".prj");

shapeFileSet.add(fileSHP);
shapeFileSet.add(fileSHX);
shapeFileSet.add(filePRJ);
shapeFileSet.add(fileDBF);

return file;
return shapeFileSet;
}
}
Empty file.
48 changes: 44 additions & 4 deletions geoportal_1/src/main/java/org/opengeoportal/download/methods/GeoToolsDownloadMethod.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

import java.io.File;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Future;

import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengeoportal.download.types.LayerRequest;
import org.opengeoportal.layer.BoundingBox;
import org.opengeoportal.solr.SolrRecord;
import org.opengeoportal.utilities.LocationFieldUtils;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.AsyncResult;

import com.vividsolutions.jts.geom.Envelope;

public class GeoToolsDownloadMethod implements PerLayerDownloadMethod {
public class GeoToolsDownloadMethod extends AbstractDownloadMethod implements PerLayerDownloadMethod {
private static final Boolean INCLUDES_METADATA = false;
private static final String METHOD = "GET";

private FeatureSourceToShape featureSourceToShape;

Expand All @@ -31,9 +35,41 @@ public void setFeatureSourceToShape(FeatureSourceToShape featureSourceToShape) {
this.featureSourceToShape = featureSourceToShape;
}

@Override
public String getMethod(){
return METHOD;
}

@Override
public Set<String> getExpectedContentType(){
Set<String> expectedContentType = new HashSet<String>();
expectedContentType.add("application/zip");
return expectedContentType;
}

@Override
public List<String> getUrls(LayerRequest layer) throws Exception{
if(LocationFieldUtils.hasArcGISRestUrl(layer.getLayerInfo().getLocation()))
{
String url = layer.getWfsUrl();
this.checkUrl(url);
return urlToUrls(url);
}

return null;

}

@Override
public String createDownloadRequest() throws Exception {
return new String("This is a dummy implementation.");
}

@Override
public Future<Set<File>> download(LayerRequest currentLayer)
throws Exception {
currentLayer.setMetadata(this.includesMetadata());

BoundingBox bbox = currentLayer.getRequestedBounds();
Envelope currentBounds = new Envelope(bbox.getMinX(), bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY());
FeatureSourceRetriever fsr = featureSourceToShape.getFeatureSourceRetriever();
Expand All @@ -55,7 +91,7 @@ public Future<Set<File>> download(LayerRequest currentLayer)
//featureSourceToShape.setFeatureCollectionBBox(currentBounds);

Set<File> fileSet = new HashSet<File>();
fileSet.add(featureSourceToShape.exportToShapefile());
fileSet.addAll(featureSourceToShape.exportToShapefiles());
return new AsyncResult<Set<File>>(fileSet);
}

Expand All @@ -64,10 +100,14 @@ public Boolean includesMetadata() {
return INCLUDES_METADATA;
}

/* Alle Lin: Should use the superclass function if derived from AbstractDownloadMethod
@Override
public Boolean hasRequiredInfo(LayerRequest layer) {
// TODO determine how to do this generically
return true;
if(LocationFieldUtils.hasArcGISRestUrl(layer.getLayerInfo().getLocation()))
return true;
return false;
}

*/
}

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
9 changes: 7 additions & 2 deletions geoportal_1/src/main/java/org/opengeoportal/download/methods/WfsDownloadMethod.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.opengeoportal.ogc.OwsInfo;
import org.opengeoportal.ogc.wfs.WfsGetFeature;
import org.opengeoportal.solr.SolrRecord;
import org.opengeoportal.utilities.LocationFieldUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -70,12 +71,16 @@ public String createDownloadRequest() throws Exception {
//really, we should check the get caps doc to see if this is a viable option...probably this should be done before/at the download prompt
String outputFormat = "shape-zip";

String request = WfsGetFeature.createWfsGetFeatureRequest(layerName, workSpace, nameSpace, outputFormat, bboxFilter);
return request;
return WfsGetFeature.createWfsGetFeatureRequest(layerName, workSpace, nameSpace, outputFormat, bboxFilter);

}

@Override
public List<String> getUrls(LayerRequest layer) throws Exception{
if(LocationFieldUtils.hasArcGISRestUrl(layer.getLayerInfo().getLocation()))
{
return null;
}
String url = layer.getWfsUrl();
this.checkUrl(url);
return urlToUrls(url);
Expand Down
14 changes: 9 additions & 5 deletions geoportal_1/src/main/java/org/opengeoportal/download/methods/WfsFeatureSourceRetriever.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.geotools.data.FeatureSource;
import org.geotools.data.simple.SimpleFeatureSource;
import org.opengeoportal.download.types.LayerRequest;
import org.opengeoportal.utilities.LocationFieldUtils;
import org.opengeoportal.utilities.OgpUtils;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
Expand All @@ -22,14 +23,17 @@ public class WfsFeatureSourceRetriever implements FeatureSourceRetriever {

@Override
public void createFeatureSourceFromLayerRequest(LayerRequest layerRequest) throws Exception{
setFeatureSource(layerRequest.getWfsUrl(), layerRequest.getLayerNameNS());
setFeatureSource(layerRequest.getWfsUrl(), layerRequest.getLayerNameNS(), LocationFieldUtils.hasArcGISRestUrl(layerRequest.getLayerInfo().getLocation()));
}

void setFeatureSource(String wfsEndPoint, String layerName) throws Exception{
void setFeatureSource(String wfsEndPoint, String layerName, Boolean isFromArcGISServer) throws Exception{
String getCapabilities = OgpUtils.combinePathWithQuery(wfsEndPoint, "REQUEST=GetCapabilities&VERSION=1.1.0");
// Both ArcGIS Server 9.3 and 10 are compliant with WFS 1.1.0, so hard-coding VERSION=1.1.0 should be fine.

Map connectionParameters = new HashMap();
Map<String, String> connectionParameters = new HashMap<String, String>();
connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL", getCapabilities );
if (isFromArcGISServer)
connectionParameters.put("WFSDataStoreFactory:WFS_STRATEGY", "arcgis");
/*
* “WFSDataStoreFactory:GET_CAPABILITIES_URL” Link to capabilities document. The implementation supports both WFS 1.0 (read/write) and WFS 1.1 (read-only).
“WFSDataStoreFactory:PROTOCOL” Optional: True for Post, False for GET, null for auto
Expand Down Expand Up @@ -57,8 +61,8 @@ void setFeatureSource(String wfsEndPoint, String layerName) throws Exception{
//find the typeName we're looking for
String typeName = "";
for (int i = 0; i < typeNames.length; i++){
if (typeNames[i].equalsIgnoreCase(layerName)){
typeName = layerName;
if (typeNames[i].contains(layerName)){
typeName = typeNames[i];
break;
}
}
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified geoportal_1/src/main/java/org/opengeoportal/layer/Envelope.java
100644 → 100755
Empty file.
Empty file.
Empty file modified geoportal_1/src/main/java/org/opengeoportal/layer/Metadata.java
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
50 changes: 43 additions & 7 deletions geoportal_1/src/main/java/org/opengeoportal/ogc/AugmentedSolrRecordRetrieverImpl.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,53 @@ private AugmentedSolrRecord addNativeTypeInfo(AugmentedSolrRecord asr, String ty
@Override
public AugmentedSolrRecord getOgcAugmentedSolrRecord(SolrRecord solrRecord) throws Exception {

AugmentedSolrRecord asr = getInfoAttempt(wmsRequester, DATA_ATTEMPTS, solrRecord);
OwsInfo wmsInfo = OwsInfo.findWmsInfo(asr.getOwsInfo());
String type = wmsInfo.getInfoMap().get("owsType");
//String qualName = wmsInfo.getWmsResponseMap().get("qualifiedName");
String owsUrl = wmsInfo.getInfoMap().get("owsUrl");
Thread.sleep(PAUSE);

String type;
String owsUrl;
AugmentedSolrRecord asr = null;

if (isArcGISServer(solrRecord))
{
//If it is from ArcGIS Server, there will be no ogcInfo associated with the ArcGIS Rest
asr = new AugmentedSolrRecord();
asr.setSolrRecord(solrRecord);

//If the mapserver is ArcGIS Server rest service, we should handle the retrieval of OWSUrl and OWS type separately.
if (LocationFieldUtils.hasWfsUrl(solrRecord.getLocation()))
{
//If it has the wfs url, downloading will come from wfs
type = "WFS";
owsUrl = LocationFieldUtils.getWfsUrl(solrRecord.getLocation());
}
else
{
//If it has only wcs url, download will come from wcs
type = "WCS";
owsUrl = LocationFieldUtils.getWcsUrl(solrRecord.getLocation());
}
}
else
{
//else, the map server is geoserver, we could query the OWS Url as normal
asr = getInfoAttempt(wmsRequester, DATA_ATTEMPTS, solrRecord);
OwsInfo wmsInfo = OwsInfo.findWmsInfo(asr.getOwsInfo());
type = wmsInfo.getInfoMap().get("owsType");
//String qualName = wmsInfo.getWmsResponseMap().get("qualifiedName");
owsUrl = wmsInfo.getInfoMap().get("owsUrl");
Thread.sleep(PAUSE);
}

return addNativeTypeInfo(asr, type, owsUrl);

}

private Boolean isArcGISServer(SolrRecord solrRecord)
{
if (LocationFieldUtils.hasArcGISRestUrl(solrRecord.getLocation())&&LocationFieldUtils.hasWfsUrl(solrRecord.getLocation()))
return true;
else
return false;
}


private AugmentedSolrRecord getInfoAttempt(OgcInfoRequester requester, int numAttempts, String layerId) throws Exception{
SolrRecord solrRecord = layerInfoRetriever.getAllLayerInfo(layerId);
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified geoportal_1/src/main/java/org/opengeoportal/ogc/OwsInfo.java
100644 → 100755
Empty file.
Empty file modified geoportal_1/src/main/java/org/opengeoportal/ogc/WmcCreator.java
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Loading