If I reformat the .prj file so that the projection is on a single line,
it works well. Is this a problem with ArcExplorer or the shapefile
writer?
David R Robison wrote:
One of the problems seems to be the generated .prj file.
Here is the file from the source shapefile:
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
Here is the file from the merged shapefile:
GEOGCS["GCS_WGS_1984",
DATUM["D_WGS_1984",
SPHEROID["WGS_1984", 6378137.0, 298.257223563]],
PRIMEM["Greenwich", 0.0],
UNIT["degree", 0.017453292519943295],
AXIS["Lon", EAST],
AXIS["Lat", NORTH]]
If I replace the merged .prj file with the source .prj file then
ArcExplorer can read the file. Any thoughts?
David Robison
Ps. I forgot to attach the source code in my previous message so here
it is...
David R Robison wrote:
I'm trying to merge multiple shapefiles into
a single shapefile. Attached is the Java code for the merge program. It
takes the target shapefile as the first command line parameter and then
a list of shapefiles to be merged together into the target file. When I
run the program, it appears to create the new shapefile, however, I
cannot open it using ESRI ArcExplorer. Any ideas what I may be doing
wrong? I am using GeoTools 2.2-RC3.
Thanks, David Robison
package com.orci.NwsNexrad;
import java.io.IOException;
import java.net.URL;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.geotools.data.FeatureStore;
import org.geotools.data.Transaction;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.feature.FeatureCollection;
/**
* @author David R Robison
* Copyright(c) 2006, Open Roads Consulting, Inc
*/
public class MergeNexradShp {
private static final Log LOG = LogFactory.getLog(MergeNexradShp.class.getName());
private ShapefileDataStore mergedData;
private Transaction mergedTransaction;
private FeatureStore mergedFeatureStore;
/**
* Constructor.
* @param newURL the URL of the new file
* @param copyURL the URL of the file to copy schema
* @throws IOException Exception
*/
public MergeNexradShp(String newURL, String copyURL) throws IOException {
mergedData = new ShapefileDataStore(new URL(newURL));
ShapefileDataStore shapefileData = new ShapefileDataStore(new URL(copyURL));
mergedData.createSchema(shapefileData.getSchema());
mergedFeatureStore = (FeatureStore)mergedData.getFeatureSource(shapefileData.getTypeNames()[0]);
mergedTransaction = mergedFeatureStore.getTransaction();
}
/**
* Read an merge a shapefile.
* @param url the file location
*/
private synchronized void mergeShapefile(String url) {
if (url == null) return;
try {
ShapefileDataStore shapefileData = new ShapefileDataStore(new URL(url));
FeatureCollection features = shapefileData.getFeatureSource().getFeatures();
System.out.println("Adding " + features.size() + " features from " + url);
mergedFeatureStore.addFeatures(features);
} catch (Exception e) {
LOG.error("Unable to load shapefile " + url + ": " + e);
e.printStackTrace();
}
}
/**
* Save the merged shapefile.
*/
public void saveShapefile() {
if (mergedTransaction == null) return;
try {
mergedTransaction.commit();
mergedTransaction.close();
System.out.println("Successfully create new shapefile with " + mergedData.getFeatureSource().getFeatures().size() + " features.");
} catch (Exception e) {
LOG.error("Unable to save shapefile: " + e);
e.printStackTrace();
}
}
/**
* Main routine.
* @param args Command line arguments
*/
public static void main(String[] args) {
try {
MergeNexradShp app = new MergeNexradShp(args[0], args[1]);
for (int i = 1; i < args.length; i++) app.mergeShapefile(args[i]);
app.saveShapefile();
} catch (Exception e) {
LOG.error("error: " + e);
e.printStackTrace();
}
}
}
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
--
David R Robison
Open Roads Consulting, Inc.
708 S. Battlefield Blvd., Chesapeake, VA 23322
phone: (757) 546-3401
e-mail: [EMAIL PROTECTED]
web: http://openroadsconsulting.com
blog: http://therobe.blogspot.com
book: http://www.xulonpress.com/bookstore/titles/1597816523.htm
|
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users