Exemple #1
0
static VALUE method_factory_write_for_psych(VALUE self, VALUE obj)
{
  RGeo_FactoryData* self_data;
  GEOSContextHandle_t self_context;
  GEOSWKTWriter* wkt_writer;
  const GEOSGeometry* geom;
  VALUE result;
  char* str;
  size_t size;
  char has_3d;
#ifndef RGEO_GEOS_SUPPORTS_SETOUTPUTDIMENSION
  RGeo_Globals* globals;
  VALUE wkt_generator;
#endif

  self_data = RGEO_FACTORY_DATA_PTR(self);
  self_context = self_data->geos_context;
  has_3d = self_data->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
#ifndef RGEO_GEOS_SUPPORTS_SETOUTPUTDIMENSION
  if (has_3d) {
    globals = self_data->globals;
    wkt_generator = globals->psych_wkt_generator;
    if (NIL_P(wkt_generator)) {
      wkt_generator = rb_funcall(
        rb_const_get_at(globals->geos_module, rb_intern("Utils")),
        rb_intern("psych_wkt_generator"), 0);
      globals->psych_wkt_generator = wkt_generator;
    }
    return rb_funcall(wkt_generator, globals->id_generate, 1, obj);
  }
#endif
  wkt_writer = self_data->psych_wkt_writer;
  if (!wkt_writer) {
    wkt_writer = GEOSWKTWriter_create_r(self_context);
    if (has_3d) {
      GEOSWKTWriter_setOutputDimension_r(self_context, wkt_writer, 3);
    }
    self_data->psych_wkt_writer = wkt_writer;
  }
  result = Qnil;
  if (wkt_writer) {
    geom = rgeo_get_geos_geometry_safe(obj);
    if (geom) {
      str = GEOSWKTWriter_write_r(self_context, wkt_writer, geom);
      if (str) {
        result = rb_str_new2(str);
        GEOSFree_r(self_context, str);
      }
    }
  }
  return result;
}
Exemple #2
0
std::string Polygon::wkt(double precision, bool bOutputZ) const
{
    GEOSWKTWriter *writer = GEOSWKTWriter_create_r(m_ctx);
    GEOSWKTWriter_setRoundingPrecision_r(m_ctx, writer, precision);
    if (bOutputZ)
        GEOSWKTWriter_setOutputDimension_r(m_ctx, writer, 3);

    char *smoothWkt = GEOSWKTWriter_write_r(m_ctx, writer, m_geom);
    std::string output(smoothWkt);
    GEOSFree_r(m_ctx, smoothWkt);
    GEOSWKTWriter_destroy_r(m_ctx, writer);
    return output;
}
Exemple #3
0
static VALUE method_geometry_as_text(VALUE self)
{
  VALUE result = Qnil;
  RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
  const GEOSGeometry* self_geom = self_data->geom;
  if (self_geom) {
    RGeo_FactoryData* factory_data = RGEO_FACTORY_DATA_PTR(self_data->factory);
    GEOSWKTWriter* wkt_writer = factory_data->wkt_writer;
    GEOSContextHandle_t geos_context = self_data->geos_context;
    if (!wkt_writer) {
      wkt_writer = GEOSWKTWriter_create_r(geos_context);
      factory_data->wkt_writer = wkt_writer;
    }
    char* str = GEOSWKTWriter_write_r(geos_context, wkt_writer, self_geom);
    if (str) {
      result = rb_str_new2(str);
      GEOSFree_r(geos_context, str);
    }
  }
  return result;
}
Exemple #4
0
static VALUE method_geometry_as_text(VALUE self)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  RGeo_FactoryData* factory_data;
  VALUE wkt_generator;
  GEOSWKTWriter* wkt_writer;
  GEOSContextHandle_t geos_context;
  char* str;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    factory_data = RGEO_FACTORY_DATA_PTR(self_data->factory);
    wkt_generator = factory_data->wkrep_wkt_generator;
    if (!NIL_P(wkt_generator)) {
      result = rb_funcall(wkt_generator, factory_data->globals->id_generate, 1, self);
    }
    else {
      wkt_writer = factory_data->wkt_writer;
      geos_context = self_data->geos_context;
      if (!wkt_writer) {
        wkt_writer = GEOSWKTWriter_create_r(geos_context);
        factory_data->wkt_writer = wkt_writer;
      }
      str = GEOSWKTWriter_write_r(geos_context, wkt_writer, self_geom);
      if (str) {
        result = rb_str_new2(str);
        GEOSFree_r(geos_context, str);
      }
    }
  }
  return result;
}