예제 #1
0
            /**
            * Add a geometry to the shapefile.
            */
            bool add(Osmium::Geometry::Geometry* geometry, ///< the geometry
                     v8::Local<v8::Object> attributes) {   ///< a %Javascript object (hash) with the attributes

                try {
                    add_geometry(geometry->create_shp_object());
                } catch (Osmium::Exception::IllegalGeometry) {
                    return false;
                }

                int ok = 0;
                for (size_t n=0; n < m_fields.size(); n++) {
                    v8::Local<v8::String> key = v8::String::New(m_fields[n].name().c_str());
                    if (attributes->HasRealNamedProperty(key)) {
                        v8::Local<v8::Value> value = attributes->GetRealNamedProperty(key);
                        if (value->IsUndefined() || value->IsNull()) {
                            DBFWriteNULLAttribute(m_dbf_handle, m_current_shape, n);
                        } else {
                            switch (m_fields[n].type()) {
                                case FTString:
                                    ok = add_string_attribute(n, value);
                                    break;
                                case FTInteger:
                                    ok = DBFWriteIntegerAttribute(m_dbf_handle, m_current_shape, n, value->Int32Value());
                                    break;
                                case FTDouble:
                                    throw std::runtime_error("fields of type double not implemented");
                                    break;
                                case FTLogical:
                                    ok = add_logical_attribute(n, value);
                                    break;
                                default:
                                    ok = 0; // should never be here
                                    break;
                            }
                            if (!ok) {
                                std::string errmsg("failed to add attribute '");
                                errmsg += m_fields[n].name();
                                errmsg += "'\n";
                                throw std::runtime_error(errmsg);
                            }
                        }
                    } else {
                        DBFWriteNULLAttribute(m_dbf_handle, m_current_shape, n);
                    }
                }
                return true;
            }
예제 #2
0
                /**
                * Add a geometry to the shapefile.
                *
                * @param shapefile shapefile the geometry is being added to
                * @param geometry geometry that should be added to the shapefile
                * @param attributes a %Javascript object (hash) with the attributes
                */
                static bool add(Osmium::Export::Shapefile* shapefile,
                                Osmium::Geometry::Geometry* geometry,
                                v8::Local<v8::Object> attributes) {

                    try {
                        shapefile->add_geometry(Osmium::Geometry::create_shp_object(*geometry));
                    } catch (Osmium::Geometry::IllegalGeometry) {
                        return false;
                    }

                    for (size_t n=0; n < shapefile->fields().size(); ++n) {
                        v8::Local<v8::String> key = v8::String::New(shapefile->field(n).name().c_str());
                        if (attributes->HasRealNamedProperty(key)) {
                            v8::Local<v8::Value> value = attributes->GetRealNamedProperty(key);
                            if (value->IsUndefined() || value->IsNull()) {
                                shapefile->add_attribute(n);
                            } else {
                                switch (shapefile->field(n).type()) {
                                    case FTString:
                                        add_string_attribute(shapefile, n, value);
                                        break;
                                    case FTInteger:
                                        shapefile->add_attribute(n, value->Int32Value());
                                        break;
                                    case FTDouble:
                                        throw std::runtime_error("fields of type double not implemented");
                                        break;
                                    case FTLogical:
                                        add_logical_attribute(shapefile, n, value);
                                        break;
                                    default:
                                        // should never be here
                                        break;
                                }
                            }
                        } else {
                            shapefile->add_attribute(n);
                        }
                    }
                    return true;
                }