Package org.bridj

Examples of org.bridj.Pointer


        }
  }

  private static void readingShp() {
    String path = "/home/mauro/Downloads/gis-test-data/10m_geography_marine_polys.shp";
        Pointer ds = OGROpen(Pointer.pointerToCString(path), 0, null);
       
       
        System.out.println(ds);
        Pointer layer = OGR_DS_GetLayerByName(ds, Pointer.pointerToCString("10m_geography_marine_polys"));
       
        Pointer hFDefn = OGR_L_GetLayerDefn(layer);
        int iField;
       
        Pointer hFeature;

        // presets the layer's features
        OGR_L_ResetReading(layer);
        while( (hFeature = OGR_L_GetNextFeature(layer)) != null)
        {
            for( iField = 0; iField < OGR_FD_GetFieldCount(hFDefn); iField++ )
            {
                Pointer hFieldDefn = OGR_FD_GetFieldDefn( hFDefn, iField );
   
                if( OGR_Fld_GetType(hFieldDefn) == OGRFieldType.OFTInteger )
                    System.out.println(OGR_F_GetFieldAsInteger( hFeature, iField ) );
                else if( OGR_Fld_GetType(hFieldDefn) == OGRFieldType.OFTReal )
                    System.out.println(OGR_F_GetFieldAsDouble( hFeature, iField) );
View Full Code Here


    void checkRoundTrip(String geometryWkt, GeometryMapper mapper) throws Exception {
        Geometry geometry = new WKTReader().read(geometryWkt);

        // to ogr and back
        Pointer ogrGeometry = mapper.parseGTGeometry(geometry);
        Geometry remapped = mapper.parseOgrGeometry(ogrGeometry);
        OGR_G_DestroyGeometry(ogrGeometry);

        assertEquals(geometry, remapped);
    }
View Full Code Here

        this.builder = new SimpleFeatureBuilder(schema);
        this.geomMapper = new GeometryMapper.WKB(geomFactory);
        this.geomFactory = geomFactory;
       
        attributeIndexes = new HashMap<String, Integer>();
        Pointer layerDefinition = OGR_L_GetLayerDefn(layer);
        int size = OGR_FD_GetFieldCount(layerDefinition);
        for(int i = 0; i < size; i++) {
            Pointer  field = OGR_FD_GetFieldDefn(layerDefinition, i);
            Pointer<Byte> namePtr = OGR_Fld_GetNameRef(field);
            String name = namePtr.getCString();
            if(targetSchema.getDescriptor(name) != null) {
                attributeIndexes.put(name, i);
            }
View Full Code Here

     * @throws DataSourceException
     */
    Pointer convertGTFeature(Pointer featureDefinition, SimpleFeature feature)
            throws IOException {
        // create a new empty OGR feature
        Pointer ogrFeature = OGR_F_Create(featureDefinition);

        // go thru GeoTools feature attributes, and convert
        SimpleFeatureType schema = feature.getFeatureType();
        for (int i = 0, j = 0; i < schema.getAttributeCount(); i++) {
            Object attribute = feature.getAttribute(i);
            if (attribute instanceof Geometry) {
                // using setGeoemtryDirectly the feature becomes the owner of the generated
                // OGR geometry and we don't have to .delete() it (it's faster, too)
                Pointer geometry = geomMapper.parseGTGeometry((Geometry) attribute);
                OGR_F_SetGeometryDirectly(ogrFeature, geometry);
            } else {
                setFieldValue(featureDefinition, ogrFeature, j, attribute);
                j++;
            }
View Full Code Here

    static void setFieldValue(Pointer featureDefinition, Pointer ogrFeature, int fieldIdx,
            Object value) throws IOException {
         if (value == null) {
            OGR_F_UnsetField(ogrFeature, fieldIdx);
        } else {
            Pointer fieldDefinition = OGR_FD_GetFieldDefn(featureDefinition, fieldIdx);
            long ogrType = OGR_Fld_GetType(fieldDefinition).value();
            if (ogrType == OGRFieldType.OFTInteger.value()) {
                OGR_F_SetFieldInteger(ogrFeature, fieldIdx, ((Number) value).intValue());
            } else if (ogrType == OGRFieldType.OFTReal.value()) {
                OGR_F_SetFieldDouble(ogrFeature, fieldIdx, ((Number) value).doubleValue());
View Full Code Here

     * @return
     * @throws IOException
     */
    SimpleFeatureType getFeatureType(Pointer layer, String typeName, String namespaceURI)
            throws IOException {
        Pointer definition = null;
        try {
            // setup the builder
            SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
            tb.setName(typeName);
            tb.setNamespaceURI(namespaceURI);
            if (tb.getNamespaceURI() == null) {
                tb.setNamespaceURI(BasicFeatureTypes.DEFAULT_NAMESPACE);
            }

            // grab the layer definition
            definition = OGR_L_GetLayerDefn(layer);

            // figure out the geometry
            Class<? extends Geometry> geometryBinding = getGeometryBinding(definition);
            if (geometryBinding != null) {
                CoordinateReferenceSystem crs = getCRS(layer);
                tb.add("the_geom", geometryBinding, crs);
            }

            // get the non geometric fields
            final int count = OGR_FD_GetFieldCount(definition);
            for (int i = 0; i < count; i++) {
                Pointer field = OGR_FD_GetFieldDefn(definition, i);
                String name = OGR_Fld_GetNameRef(field).getCString();
                Class binding = getBinding(field);
                int width = OGR_Fld_GetWidth(field);
                if (width > 0) {
                    tb.length(width);
View Full Code Here

     * @param ad
     * @throws IOException
     */
    public Pointer getOGRFieldDefinition(AttributeDescriptor ad) throws IOException {
        final Class type = ad.getType().getBinding();
        final Pointer def;
        Pointer<Byte> namePtr = pointerToCString(ad.getLocalName());
        if (Boolean.class.equals(type)) {
            def = OGR_Fld_Create(namePtr, OGRFieldType.OFTString);
            OGR_Fld_SetWidth(def, 5);
        } else if (Byte.class.equals(type)) {
View Full Code Here

     * @param layer
     * @return
     * @throws IOException
     */
    private CoordinateReferenceSystem getCRS(Pointer layer) throws IOException {
        Pointer spatialReference = null;
        CoordinateReferenceSystem crs = null;
        try {
            spatialReference = OGR_L_GetSpatialRef(layer);
            if (spatialReference == null) {
                return null;
View Full Code Here

     * @return
     * @throws IOException
     */
    SimpleFeatureType getFeatureType(Pointer layer, String typeName, String namespaceURI)
            throws IOException {
        Pointer definition = null;
        try {
            // setup the builder
            SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
            tb.setName(typeName);
            tb.setNamespaceURI(namespaceURI);
            if (tb.getNamespaceURI() == null) {
                tb.setNamespaceURI(BasicFeatureTypes.DEFAULT_NAMESPACE);
            }

            // grab the layer definition
            definition = OGR_L_GetLayerDefn(layer);

            // figure out the geometry
            Class<? extends Geometry> geometryBinding = getGeometryBinding(definition);
            if (geometryBinding != null) {
                CoordinateReferenceSystem crs = getCRS(layer);
                tb.add("the_geom", geometryBinding, crs);
            }

            // get the non geometric fields
            final int count = OGR_FD_GetFieldCount(definition);
            for (int i = 0; i < count; i++) {
                Pointer field = OGR_FD_GetFieldDefn(definition, i);
                String name = OGR_Fld_GetNameRef(field).getCString();
                Class binding = getBinding(field);
                int width = OGR_Fld_GetWidth(field);
                if (width > 0) {
                    tb.length(width);
View Full Code Here

     * @param ad
     * @throws IOException
     */
    public Pointer getOGRFieldDefinition(AttributeDescriptor ad) throws IOException {
        final Class type = ad.getType().getBinding();
        final Pointer def;
        Pointer<Byte> namePtr = pointerToCString(ad.getLocalName());
        if (Boolean.class.equals(type)) {
            def = OGR_Fld_Create(namePtr, OGRFieldType.OFTString);
            OGR_Fld_SetWidth(def, 5);
        } else if (Byte.class.equals(type)) {
View Full Code Here

TOP

Related Classes of org.bridj.Pointer

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.