Package org.geotools.data.shapefile.files

Examples of org.geotools.data.shapefile.files.StorageFile


        } else {
            throw new DataSourceException("Cannot create a shapefile whose geometry type is "
                    + geomType);
        }

        StorageFile shpStoragefile = shpFiles.getStorageFile(SHP);
        StorageFile shxStoragefile = shpFiles.getStorageFile(SHX);
        StorageFile dbfStoragefile = shpFiles.getStorageFile(DBF);
        StorageFile prjStoragefile = shpFiles.getStorageFile(PRJ);

        FileChannel shpChannel = shpStoragefile.getWriteChannel();
        FileChannel shxChannel = shxStoragefile.getWriteChannel();

        ShapefileWriter writer = new ShapefileWriter(shpChannel, shxChannel);
        try {
            // by spec, if the file is empty, the shape envelope should be ignored
            writer.writeHeaders(new Envelope(), shapeType, 0, 100);
        } finally {
            writer.close();
            assert !shpChannel.isOpen();
            assert !shxChannel.isOpen();
        }

        DbaseFileHeader dbfheader = createDbaseHeader(featureType);

        dbfheader.setNumRecords(0);

        WritableByteChannel dbfChannel = dbfStoragefile.getWriteChannel();

        try {
            dbfheader.writeHeader(dbfChannel);
        } finally {
            dbfChannel.close();
        }

        if (crs != null) {
            String s = toSingleLineWKT(crs);

            FileWriter prjWriter = new FileWriter(prjStoragefile.getFile());
            try {
                prjWriter.write(s);
            } finally {
                prjWriter.close();
            }
View Full Code Here


    public void forceSchemaCRS(CoordinateReferenceSystem crs) throws IOException {
        if (crs == null)
            throw new NullPointerException("CRS required for .prj file");

        String s = toSingleLineWKT(crs);
        StorageFile storageFile = shpFiles.getStorageFile(PRJ);
        FileWriter out = new FileWriter(storageFile.getFile());

        try {
            out.write(s);
        } finally {
            out.close();
        }
        storageFile.replaceOriginal();
        entries.clear();
    }
View Full Code Here

    public static void generate(ShpFiles shpFiles) throws IOException {
        LOGGER.fine("Generating fids for " + shpFiles.get(SHP));

       
        IndexFile indexFile = null;
        StorageFile file = shpFiles.getStorageFile(FIX);
        IndexedFidWriter writer = null;
       
        try {
            indexFile = new IndexFile(shpFiles, false);

            // writer closes channel for you.
            writer = new IndexedFidWriter(shpFiles, file);

            for (int i = 0, j = indexFile.getRecordCount(); i < j; i++) {
                writer.next();
            }

        } finally {
            try {
                if (writer != null) {
                    writer.close();
                }
                file.replaceOriginal();
            } finally {
                if (indexFile != null) {
                    indexFile.close();
                }
            }
View Full Code Here

        }
    }

    @Test
    public void testGetStorageFile() throws Exception {
        StorageFile prj = files.getStorageFile(PRJ);
        assertTrue(prj.getFile().getName().startsWith(typeName));
        assertTrue(prj.getFile().getName().endsWith(".prj"));
    }
View Full Code Here

        super(indexes.shpFiles, featureReader, charset, timeZone);
        this.indexes = indexes;
        if (!indexes.shpFiles.isLocal()) {
            this.fidWriter = IndexedFidWriter.EMPTY_WRITER;
        } else {
            StorageFile storageFile = shpFiles.getStorageFile(FIX);
            storageFiles.put(FIX, storageFile);
            this.fidWriter = new IndexedFidWriter(shpFiles, storageFile);
        }
    }
View Full Code Here

        int cnt = 0;

        ShapefileReader reader = null;

        // Temporary file for building...
        StorageFile storage = shpFiles.getStorageFile(ShpFileType.QIX);
        File treeFile = storage.getFile();

        try {
            reader = new ShapefileReader(shpFiles, true, false, new GeometryFactory());
           
            if(max == -1) {
                // compute a reasonable index max depth, considering a fully developed
                // 10 levels one already contains 200k index nodes, good for indexing up
                // to 3M features without consuming too much memory
                int features = reader.getCount(0);
                max = 1;
                int nodes = 1;
                while(nodes * leafSize < features) {
                    max++;
                    nodes *= 4;
                }
                if(max < 10) {
                    max = 10;
                }
               
                reader.close();
                reader = new ShapefileReader(shpFiles, true, false, new GeometryFactory());
            }
           
            cnt = this.buildQuadTree(reader, treeFile, verbose);
        } finally {
            if (reader != null)
                reader.close();
        }

        // Final index file
        storage.replaceOriginal();

        return cnt;
    }
View Full Code Here

    @Test
    public void testReplaceOriginal() throws Exception {
        ShpFiles files1 = shpFiles1;
        ShpFileType type = PRJ;
        StorageFile storagePRJ1 = files1.getStorageFile(type);
        File original = storagePRJ1.getFile();
       
        try {
          String writtenToStorageFile = "Copy";
 
          writeData(storagePRJ1, writtenToStorageFile);
 
          storagePRJ1.replaceOriginal();
          assertEquals(0, files1.numberOfLocks());
 
          assertCorrectData(files1, type, writtenToStorageFile);
        } catch(Exception e) {
          storagePRJ1.getFile().delete();
          original.delete();
        }
    }
View Full Code Here

    }

    @Test
    public void testReplaceOriginals() throws Exception {

        StorageFile storagePRJ1 = shpFiles1.getStorageFile(PRJ);
        StorageFile storageSHP1 = shpFiles1.getStorageFile(SHP);
        StorageFile storagePRJ2 = shpFiles2.getStorageFile(PRJ);
        StorageFile storageSHP2 = shpFiles2.getStorageFile(SHP);

        try {
          String sPRJ1 = "storagePRJ1";
          String sSHP1 = "storageSHP1";
          String sPRJ2 = "storagePRJ2";
          String sSHP2 = "storageSHP2";
 
          writeData(storagePRJ1, sPRJ1);
          writeData(storageSHP1, sSHP1);
          writeData(storagePRJ2, sPRJ2);
          writeData(storageSHP2, sSHP2);
 
          StorageFile.replaceOriginals(storagePRJ1, storagePRJ2, storageSHP1,
                  storageSHP2, storageSHP2);
 
          this.assertCorrectData(shpFiles1, PRJ, sPRJ1);
          this.assertCorrectData(shpFiles1, SHP, sSHP1);
          this.assertCorrectData(shpFiles2, PRJ, sPRJ2);
          this.assertCorrectData(shpFiles2, SHP, sSHP2);
 
          assertEquals(0, shpFiles1.numberOfLocks());
          assertEquals(0, shpFiles2.numberOfLocks());
        } finally {
          storagePRJ1.getFile().delete();
          storagePRJ2.getFile().delete();
          storageSHP1.getFile().delete();
          storageSHP2.getFile().delete();
        }
    }
View Full Code Here

    }

    @Test
    public void testCompareTo() throws IOException {
        StorageFile storagePRJ1 = shpFiles1.getStorageFile(PRJ);
        StorageFile storageSHP1 = shpFiles1.getStorageFile(SHP);
        StorageFile storagePRJ2 = shpFiles2.getStorageFile(PRJ);
        StorageFile storageSHP2 = shpFiles2.getStorageFile(SHP);

        try {
          assertFalse(storagePRJ1.compareTo(storageSHP1) == 0);
          assertFalse(storagePRJ1.compareTo(storagePRJ2) == 0);
 
          StorageFile[] array = new StorageFile[] { storagePRJ1, storagePRJ2,
                  storageSHP1, storageSHP2 };
 
          Arrays.sort(array);
 
          assertFalse(array[0].compareTo(array[1]) == 0);
          assertFalse(array[2].compareTo(array[3]) == 0);
          assertFalse(array[1].compareTo(array[2]) == 0);
        } finally {
          storagePRJ1.getFile().delete();
          storagePRJ2.getFile().delete();
          storageSHP1.getFile().delete();
          storageSHP2.getFile().delete();
        }
    }
View Full Code Here

TOP

Related Classes of org.geotools.data.shapefile.files.StorageFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.