示例#1
0
/*------------------------------------------------------------------------
 * create
 */
ogc_order * ogc_order :: create(
   int         value,
   ogc_error * err)
{
   ogc_order * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( value <= 0 || value > 3 )
   {
      ogc_error::set(err, OGC_ERR_INVALID_ORDER_VALUE, obj_kwd(), value);
      bad = true;
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_order();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      p->_obj_type = OGC_OBJ_TYPE_ORDER;
      p->_visible  = true;
      p->_value    = value;
   }

   return p;
}
/*------------------------------------------------------------------------
 * create
 */
ogc_bbox_extent * ogc_bbox_extent :: create(
   double        ll_lat,
   double        ll_lon,
   double        ur_lat,
   double        ur_lon,
   ogc_error *   err)
{
   ogc_bbox_extent * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( ll_lat <  -90.0 || ll_lat >  90.0 )
   {
      ogc_error::set(err, OGC_ERR_INVALID_LATITUDE,  obj_kwd(), ll_lat);
      bad = true;
   }

   if ( ur_lat <  -90.0 || ur_lat >  90.0 )
   {
      ogc_error::set(err, OGC_ERR_INVALID_LATITUDE,  obj_kwd(), ur_lat);
      bad = true;
   }

   if ( ll_lon < -180.0 || ll_lon > 180.0 )
   {
      ogc_error::set(err, OGC_ERR_INVALID_LONGITUDE, obj_kwd(), ll_lon);
      bad = true;
   }

   if ( ur_lon < -180.0 || ur_lon > 180.0 )
   {
      ogc_error::set(err, OGC_ERR_INVALID_LONGITUDE, obj_kwd(), ur_lon);
      bad = true;
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_bbox_extent();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      p->_obj_type = OGC_OBJ_TYPE_BBOX_EXTENT;
      p->_visible  = true;
      p->_ll_lat   = ll_lat;
      p->_ll_lon   = ll_lon;
      p->_ur_lat   = ur_lat;
      p->_ur_lon   = ur_lon;
   }

   return p;
}
/*------------------------------------------------------------------------
 * create
 */
ogc_image_datum * ogc_image_datum :: create(
   const char *    name,
   ogc_pixel_type  pixel_type,
   ogc_anchor *    anchor,
   ogc_vector *    ids,
   ogc_error *     err)
{
   ogc_image_datum * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( name == OGC_NULL )
   {
      name = "";
   }
   else
   {
      int len = ogc_string::unescape_len(name);
      if ( len >= OGC_NAME_MAX )
      {
         ogc_error::set(err, OGC_ERR_NAME_TOO_LONG, obj_kwd(), len);
         bad = true;
      }
   }

   if ( !ogc_utils::pixel_type_valid(pixel_type) )
   {
      ogc_error::set(err, OGC_ERR_INVALID_PIXEL_TYPE,
         obj_kwd(), static_cast<int>(pixel_type));
      bad = true;
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_image_datum();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      ogc_string::unescape_str(p->_name, name, OGC_NAME_MAX);
      p->_obj_type   = OGC_OBJ_TYPE_IMAGE_DATUM;
      p->_visible    = true;
      p->_datum_type = OGC_DATUM_TYPE_IMAGE;
      p->_pixel_type = pixel_type;
      p->_anchor     = anchor;
      p->_ids        = ids;
   }

   return p;
}
/*------------------------------------------------------------------------
 * create
 */
ogc_deriving_conv * ogc_deriving_conv :: create(
    const char * name,
    ogc_method * method,
    ogc_vector * parameters,
    ogc_vector * param_files,
    ogc_vector * ids,
    ogc_error *  err)
{
    ogc_deriving_conv * p = OGC_NULL;
    bool bad = false;

    /*---------------------------------------------------------
     * error checks
     */
    if ( name == OGC_NULL )
    {
        name = "";
    }
    else
    {
        int len = ogc_string::unescape_len(name);
        if ( len >= OGC_NAME_MAX )
        {
            ogc_error::set(err, OGC_ERR_NAME_TOO_LONG, obj_kwd(), len);
            bad = true;
        }
    }

    if ( method == OGC_NULL )
    {
        ogc_error::set(err, OGC_ERR_MISSING_METHOD, obj_kwd());
        bad = true;
    }

    /*---------------------------------------------------------
     * create the object
     */
    if ( !bad )
    {
        p = new (std::nothrow) ogc_deriving_conv();
        if ( p == OGC_NULL )
        {
            ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
            return p;
        }

        ogc_string::unescape_str(p->_name, name, OGC_NAME_MAX);
        p->_obj_type    = OGC_OBJ_TYPE_DERIVING_CONV;
        p->_visible     = true;
        p->_method      = method;
        p->_parameters  = parameters;
        p->_param_files = param_files;
        p->_ids         = ids;
    }

    return p;
}
/*------------------------------------------------------------------------
 * create
 */
ogc_geod_datum * ogc_geod_datum :: create(
   const char *    name,
   ogc_ellipsoid * ellipsoid,
   ogc_anchor *    anchor,
   ogc_vector *    ids,
   ogc_error *     err)
{
   ogc_geod_datum * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( name == OGC_NULL )
   {
      name = "";
   }
   else
   {
      int len = ogc_string::unescape_len(name);
      if ( len >= OGC_NAME_MAX )
      {
         ogc_error::set(err, OGC_ERR_NAME_TOO_LONG, obj_kwd(), len);
         bad = true;
      }
   }

   if ( ellipsoid == OGC_NULL )
   {
      ogc_error::set(err, OGC_ERR_MISSING_ELLIPSOID, obj_kwd());
      bad = true;
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_geod_datum();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      ogc_string::unescape_str(p->_name, name, OGC_NAME_MAX);
      p->_obj_type   = OGC_OBJ_TYPE_GEOD_DATUM;
      p->_visible    = true;
      p->_datum_type = OGC_DATUM_TYPE_GEOD;
      p->_ellipsoid  = ellipsoid;
      p->_anchor     = anchor;
      p->_ids        = ids;
   }

   return p;
}
示例#6
0
/*------------------------------------------------------------------------
 * create
 */
ogc_lenunit * ogc_lenunit :: create(
   const char * name,
   double       factor,
   ogc_vector * ids,
   ogc_error *  err)
{
   ogc_lenunit * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( name == OGC_NULL )
   {
      name = "";
   }
   else
   {
      int len = ogc_string::unescape_len(name);
      if ( len >= OGC_NAME_MAX )
      {
         ogc_error::set(err, OGC_ERR_NAME_TOO_LONG, obj_kwd(), len);
         bad = true;
      }
   }

   if ( factor <= 0.0 )
   {
      ogc_error::set(err, OGC_ERR_INVALID_UNIT_FACTOR, obj_kwd(), factor);
      bad = true;
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_lenunit();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      ogc_string::unescape_str(p->_name, name, OGC_NAME_MAX);
      p->_obj_type  = OGC_OBJ_TYPE_LENUNIT;
      p->_visible   = true;
      p->_unit_type = OGC_UNIT_TYPE_LENGTH;
      p->_factor    = factor;
      p->_ids       = ids;
   }

   return p;
}
/*------------------------------------------------------------------------
 * create
 */
ogc_base_vert_crs * ogc_base_vert_crs :: create(
   const char *      name,
   ogc_vert_datum *  datum,
   ogc_unit *        unit,
   ogc_error *       err)
{
   ogc_base_vert_crs * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( name == OGC_NULL )
   {
      name = "";
   }
   else
   {
      int len = ogc_string::unescape_len(name);
      if ( len >= OGC_NAME_MAX )
      {
         ogc_error::set(err, OGC_ERR_NAME_TOO_LONG, obj_kwd(), len);
         bad = true;
      }
   }

   if ( datum == OGC_NULL )
   {
      ogc_error::set(err, OGC_ERR_MISSING_DATUM, obj_kwd());
      bad = true;
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_base_vert_crs();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      ogc_string::unescape_str(p->_name, name, OGC_NAME_MAX);
      p->_obj_type = OGC_OBJ_TYPE_BASE_VERT_CRS;
      p->_visible  = true;
      p->_crs_type = OGC_CRS_TYPE_BASE_VERT;
      p->_datum    = datum;
      p->_unit     = unit;
   }

   return p;
}
/*------------------------------------------------------------------------
 * create
 */
ogc_parameter * ogc_parameter :: create(
   const char * name,
   double       value,
   ogc_unit *   unit,
   ogc_vector * ids,
   ogc_error *  err)
{
   ogc_parameter * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( name == OGC_NULL )
   {
      ogc_error::set(err, OGC_ERR_EMPTY_NAME, obj_kwd());
      bad = true;
   }
   else
   {
      int len = ogc_string::unescape_len(name);
      if ( len >= OGC_NAME_MAX )
      {
         ogc_error::set(err, OGC_ERR_NAME_TOO_LONG, obj_kwd(), len);
         bad = true;
      }
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_parameter();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      ogc_string::unescape_str(p->_name, name, OGC_NAME_MAX);
      p->_obj_type = OGC_OBJ_TYPE_PARAMETER;
      p->_value    = value;
      p->_unit     = unit;
      p->_ids      = ids;
   }

   return p;
}
/*------------------------------------------------------------------------
 * create
 */
ogc_vert_extent * ogc_vert_extent :: create(
   double        min_ht,
   double        max_ht,
   ogc_lenunit * lenunit,
   ogc_error *   err)
{
   ogc_vert_extent * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_vert_extent();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      p->_obj_type = OGC_OBJ_TYPE_VERT_EXTENT;
      p->_visible  = true;
      p->_min_ht   = min_ht;
      p->_max_ht   = max_ht;
      p->_lenunit  = lenunit;
   }

   return p;
}
示例#10
0
/*------------------------------------------------------------------------
 * create
 */
ogc_cs * ogc_cs :: create(
   ogc_cs_type  cs_type,
   int          dimension,
   ogc_vector * ids,
   ogc_error *  err)
{
   ogc_cs *  p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( !ogc_utils::cs_type_valid(cs_type) )
   {
      ogc_error::set(err, OGC_ERR_INVALID_CS_TYPE, obj_kwd(),
         static_cast<int>(cs_type));
      bad = true;
   }

   if ( dimension < 0 || dimension > 3 )
   {
      ogc_error::set(err, OGC_ERR_INVALID_DIMENSION, obj_kwd(), dimension);
      bad = true;
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_cs();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      p->_obj_type  = OGC_OBJ_TYPE_CS;
      p->_visible   = true;
      p->_cs_type   = cs_type;
      p->_dimension = dimension;
      p->_ids       = ids;
   }

   return p;
}
示例#11
0
/*------------------------------------------------------------------------
 * create
 */
ogc_method * ogc_method :: create(
   const char * name,
   ogc_vector * ids,
   ogc_error *  err)
{
   ogc_method * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( name == OGC_NULL || *name == 0 )
   {
      ogc_error::set(err, OGC_ERR_EMPTY_NAME, obj_kwd());
      bad = true;
   }
   else
   {
      int len = ogc_string::unescape_len(name);
      if ( len >= OGC_NAME_MAX )
      {
         ogc_error::set(err, OGC_ERR_NAME_TOO_LONG, obj_kwd(), len);
         bad = true;
      }
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_method();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      ogc_string::unescape_str(p->_name, name, OGC_NAME_MAX);
      p->_obj_type = OGC_OBJ_TYPE_METHOD;
      p->_visible  = true;
      p->_ids      = ids;
   }

   return p;
}
bool ogc_base_geod_crs :: to_wkt(
    char      buffer[],
    int       options,
    size_t    buflen) const
{
    OGC_UTF8_NAME buf_name;
    OGC_TBUF      buf_hdr;
    OGC_TBUF      buf_datum;
    OGC_TBUF      buf_primem;
    OGC_TBUF      buf_unit;
    int           opts  =  (options | OGC_WKT_OPT_INTERNAL);
    size_t        len   = 0;
    bool          rc    = true;
    const char *  opn   = "[";
    const char *  cls   = "]";
    const char *  kwd   = obj_kwd();

    if ( (options & OGC_WKT_OPT_PARENS) != 0 )
    {
        opn = "(";
        cls = ")";
    }

    if ( (opts & OGC_WKT_OPT_TOP_ID_ONLY) != 0 )
        opts |= OGC_WKT_OPT_NO_IDS;

    if ( buffer == OGC_NULL )
        return false;
    *buffer = 0;

    if ( !is_visible() )
        return true;

    if ( (opts & OGC_WKT_OPT_OLD_SYNTAX) != 0 )
        kwd = old_kwd();

    rc &= ogc_geod_datum :: to_wkt(_datum,  buf_datum,  opts, OGC_TBUF_MAX);
    rc &= ogc_primem     :: to_wkt(_primem, buf_primem, opts, OGC_TBUF_MAX);
    rc &= ogc_unit       :: to_wkt(_unit,   buf_unit,   opts, OGC_TBUF_MAX);

    ogc_string::escape_str(buf_name, _name, OGC_UTF8_NAME_MAX);
    sprintf(buf_hdr, "%s%s\"%s\"",
            kwd, opn, buf_name);

    OGC_CPY_TO_BUF( buf_hdr    );
    OGC_ADD_TO_BUF( buf_datum  );
    OGC_ADD_TO_BUF( buf_primem );
    OGC_ADD_TO_BUF( buf_unit   );
    OGC_CPY_TO_BUF( cls        );

    if ( (options & OGC_WKT_OPT_INTERNAL) == 0 &&
            (options & OGC_WKT_OPT_EXPAND)   != 0 )
    {
        rc &= ogc_utils :: expand_wkt(buffer, buffer, "", options, buflen);
    }

    return rc;
}
示例#13
0
/*------------------------------------------------------------------------
 * object to WKT
 */
bool ogc_method :: to_wkt_projection(
   char      buffer[],
   int       options,
   size_t    buflen) const
{
   OGC_UTF8_NAME buf_name;
   OGC_TBUF      buf_hdr;
   OGC_TBUF      buf_id;
   int           opts  =  (options | OGC_WKT_OPT_INTERNAL);
   size_t        len   = 0;
   bool          rc    = true;
   const char *  opn   = "[";
   const char *  cls   = "]";
   const char *  kwd   = obj_kwd();

   if ( (options & OGC_WKT_OPT_PARENS) != 0 )
   {
      opn = "(";
      cls = ")";
   }

   if ( (opts & OGC_WKT_OPT_TOP_ID_ONLY) != 0 )
      opts |= OGC_WKT_OPT_NO_IDS;

   if ( buffer == OGC_NULL )
      return false;
   *buffer = 0;

   if ( (opts & OGC_WKT_OPT_OLD_SYNTAX) != 0 )
      kwd = alt_kwd();

   ogc_string::escape_str(buf_name, _name, OGC_UTF8_NAME_MAX);
   sprintf(buf_hdr, "%s%s\"%s\"",
      kwd, opn, buf_name);

   OGC_CPY_TO_BUF( buf_hdr );

   if ( _ids != OGC_NULL && (options & OGC_WKT_OPT_NO_IDS) == 0 )
   {
      for (int i = 0; i < id_count(); i++)
      {
         rc &= ogc_id :: to_wkt(id(i), buf_id, opts, OGC_TBUF_MAX);
         OGC_ADD_TO_BUF( buf_id );
         if ( (opts & OGC_WKT_OPT_OLD_SYNTAX) != 0 )
            break;
      }
   }

   OGC_CPY_TO_BUF( cls );

   if ( (options & OGC_WKT_OPT_INTERNAL) == 0 &&
        (options & OGC_WKT_OPT_EXPAND)   != 0 )
   {
      rc &= ogc_utils :: expand_wkt(buffer, buffer, "", options, buflen);
   }

   return rc;
}
示例#14
0
/*------------------------------------------------------------------------
 * create
 */
ogc_time_origin * ogc_time_origin :: create(
   const char *   origin,
   ogc_error *    err)
{
   ogc_time_origin * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( origin == OGC_NULL )
   {
      origin = "";
   }
   else
   {
      int len = ogc_string::unescape_len(origin);
      if ( len >= OGC_TIME_MAX )
      {
         ogc_error::set(err, OGC_ERR_TIME_TOO_LONG, obj_kwd(), len);
         bad = true;
      }
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_time_origin();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      ogc_string::unescape_str(p->_origin, origin, OGC_TIME_MAX);
      p->_obj_type = OGC_OBJ_TYPE_TIME_ORIGIN;
      p->_visible  = true;
   }

   return p;
}
示例#15
0
/*------------------------------------------------------------------------
 * create
 */
ogc_scope * ogc_scope :: create(
   const char * text,
   ogc_error *  err)
{
   ogc_scope * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( text == OGC_NULL )
   {
      text = "";
   }
   else
   {
      int len = ogc_string::unescape_len(text);
      if ( len >= OGC_TEXT_MAX )
      {
         ogc_error::set(err, OGC_ERR_TEXT_TOO_LONG, obj_kwd(), len);
         bad = true;
      }
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_scope();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      ogc_string::unescape_str(p->_text, text, OGC_TEXT_MAX);
      p->_obj_type = OGC_OBJ_TYPE_SCOPE;
      p->_visible  = true;
   }

   return p;
}
示例#16
0
bool ogc_meridian :: to_wkt(
   char      buffer[],
   int       options,
   size_t    buflen) const
{
   OGC_TBUF     buf_angunit;
   OGC_TBUF     buf_hdr;
   OGC_NBUF     buf_value;
   int          opts  =  (options | OGC_WKT_OPT_INTERNAL);
   size_t       len   = 0;
   bool         rc    = true;
   const char * opn   = "[";
   const char * cls   = "]";
   const char *  kwd   = obj_kwd();

   if ( (options & OGC_WKT_OPT_PARENS) != 0 )
   {
      opn = "(";
      cls = ")";
   }

   if ( (opts & OGC_WKT_OPT_TOP_ID_ONLY) != 0 )
      opts |= OGC_WKT_OPT_NO_IDS;

   if ( buffer == OGC_NULL )
      return false;
   *buffer = 0;

   if ( !is_visible() )
      return true;

   if ( (options & OGC_WKT_OPT_OLD_SYNTAX) != 0 )
      return true;

   ogc_string :: dtoa(_value, buf_value);

   rc &= ogc_angunit :: to_wkt(_angunit, buf_angunit, opts, OGC_TBUF_MAX);

   sprintf(buf_hdr, "%s%s%s",
      kwd, opn, buf_value);

   OGC_CPY_TO_BUF( buf_hdr     );
   OGC_ADD_TO_BUF( buf_angunit );
   OGC_CPY_TO_BUF( cls         );

   if ( (options & OGC_WKT_OPT_INTERNAL) == 0 &&
        (options & OGC_WKT_OPT_EXPAND)   != 0 )
   {
      rc &= ogc_utils :: expand_wkt(buffer, buffer, "", options, buflen);
   }

   return rc;
}
示例#17
0
/*------------------------------------------------------------------------
 * object from tokens
 */
ogc_crs * ogc_crs :: from_tokens(
   const ogc_token * t,
   int               start,
   int *             pend,
   ogc_error *       err)
{
   if ( t == OGC_NULL )
   {
      ogc_error::set(err, OGC_ERR_WKT_EMPTY_STRING, obj_kwd());
      return OGC_NULL;
   }

   const char * kwd = t->_arr[start].str;

#  define CHECK(n) \
   if ( ogc_##n::is_kwd(kwd) ) \
      return ogc_##n :: from_tokens(t, start, pend, err)

   CHECK( engr_crs       );
   CHECK( geod_crs       );
   CHECK( image_crs      );
   CHECK( param_crs      );
   CHECK( proj_crs       );
   CHECK( time_crs       );
   CHECK( vert_crs       );
   CHECK( compound_crs   );

   CHECK( base_engr_crs  );
   CHECK( base_geod_crs  );
   CHECK( base_param_crs );
   CHECK( base_proj_crs  );
   CHECK( base_time_crs  );
   CHECK( base_vert_crs  );

#  undef CHECK

   ogc_error::set(err, OGC_ERR_WKT_INVALID_KEYWORD, obj_kwd(), kwd);
   return OGC_NULL;
}
/*------------------------------------------------------------------------
 * object from WKT
 */
ogc_object* ogc_object :: from_wkt(
   const char * wkt,
   ogc_error *  err)
{
   ogc_token t;

   if ( ! t.tokenize(wkt, obj_kwd(), err) )
   {
      return OGC_NULL;
   }

   return from_tokens(&t, 0, OGC_NULL, err);
}
示例#19
0
bool ogc_bbox_extent :: to_wkt(
   char      buffer[],
   int       options,
   size_t    buflen) const
{
   OGC_TBUF      buf_hdr;
   OGC_NBUF      buf_ll_lat;
   OGC_NBUF      buf_ll_lon;
   OGC_NBUF      buf_ur_lat;
   OGC_NBUF      buf_ur_lon;
   size_t        len   = 0;
   bool          rc    = true;
   const char *  opn   = "[";
   const char *  cls   = "]";
   const char *  kwd   = obj_kwd();

   if ( (options & OGC_WKT_OPT_PARENS) != 0 )
   {
      opn = "(";
      cls = ")";
   }

   if ( buffer == OGC_NULL )
      return false;
   *buffer = 0;

   if ( !is_visible() )
      return true;

   if ( (options & OGC_WKT_OPT_OLD_SYNTAX) != 0 )
      return true;

   ogc_string :: dtoa(_ll_lat, buf_ll_lat);
   ogc_string :: dtoa(_ll_lon, buf_ll_lon);
   ogc_string :: dtoa(_ur_lat, buf_ur_lat);
   ogc_string :: dtoa(_ur_lon, buf_ur_lon);

   sprintf(buf_hdr, "%s%s%s,%s,%s,%s",
      kwd, opn, buf_ll_lat, buf_ll_lon, buf_ur_lat, buf_ur_lon);

   OGC_CPY_TO_BUF( buf_hdr );
   OGC_CPY_TO_BUF( cls     );

   if ( (options & OGC_WKT_OPT_INTERNAL) == 0 &&
        (options & OGC_WKT_OPT_EXPAND)   != 0 )
   {
      rc &= ogc_utils :: expand_wkt(buffer, buffer, "", options, buflen);
   }

   return rc;
}
/*------------------------------------------------------------------------
 * object from WKT
 */
ogc_base_geod_crs * ogc_base_geod_crs :: from_wkt(
    const char * wkt,
    ogc_error *  err)
{
    ogc_base_geod_crs * obj = OGC_NULL;
    ogc_token t;

    if ( t.tokenize(wkt, obj_kwd(), err) )
    {
        obj = from_tokens(&t, 0, OGC_NULL, err);
    }

    return obj;
}
示例#21
0
/*------------------------------------------------------------------------
 * object from WKT
 */
ogc_meridian * ogc_meridian :: from_wkt(
   const char * wkt,
   ogc_error *  err)
{
   ogc_meridian * obj = OGC_NULL;
   ogc_token t;

   if ( t.tokenize(wkt, obj_kwd(), err) )
   {
      obj = from_tokens(&t, 0, OGC_NULL, err);
   }

   return obj;
}
示例#22
0
/*------------------------------------------------------------------------
 * create
 */
ogc_meridian * ogc_meridian :: create(
   double        value,
   ogc_angunit * angunit,
   ogc_error *   err)
{
   ogc_meridian * p = OGC_NULL;
   bool bad = false;

   /*---------------------------------------------------------
    * error checks
    */
   if ( value <= -360.0 || value >= 360.0 )
   {
      ogc_error::set(err, OGC_ERR_INVALID_MERIDIAN_VALUE, obj_kwd(), value);
      bad = true;
   }

   /*---------------------------------------------------------
    * create the object
    */
   if ( !bad )
   {
      p = new (std::nothrow) ogc_meridian();
      if ( p == OGC_NULL )
      {
         ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
         return p;
      }

      p->_obj_type = OGC_OBJ_TYPE_MERIDIAN;
      p->_visible  = true;
      p->_value    = value;
      p->_angunit  = angunit;
   }

   return p;
}
示例#23
0
bool ogc_scope :: to_wkt(
   char      buffer[],
   int       options,
   size_t    buflen) const
{
   OGC_UTF8_TEXT buf_text;
   OGC_TBUF      buf_hdr;
   size_t        len   = 0;
   bool          rc    = true;
   const char *  opn   = "[";
   const char *  cls   = "]";
   const char *  kwd   = obj_kwd();

   if ( (options & OGC_WKT_OPT_PARENS) != 0 )
   {
      opn = "(";
      cls = ")";
   }

   if ( buffer == OGC_NULL )
      return false;
   *buffer = 0;

   if ( !is_visible() )
      return true;

   if ( (options & OGC_WKT_OPT_OLD_SYNTAX) != 0 )
      return true;

   ogc_string::escape_str(buf_text, _text, OGC_UTF8_TEXT_MAX);
   sprintf(buf_hdr, "%s%s\"%s\"",
      kwd, opn, buf_text);

   OGC_CPY_TO_BUF( buf_hdr );
   OGC_CPY_TO_BUF( cls     );

   if ( (options & OGC_WKT_OPT_INTERNAL) == 0 &&
        (options & OGC_WKT_OPT_EXPAND)   != 0 )
   {
      rc &= ogc_utils :: expand_wkt(buffer, buffer, "", options, buflen);
   }

   return rc;
}
示例#24
0
/*------------------------------------------------------------------------
 * object from tokens
 */
ogc_meridian * ogc_meridian :: from_tokens(
   const ogc_token * t,
   int               start,
   int *             pend,
   ogc_error *       err)
{
   const ogc_token_entry * arr;
   const char * kwd;
   bool bad = false;
   int  level;
   int  end;
   int  same;
   int  num;

   ogc_meridian * obj     = OGC_NULL;
   ogc_angunit *  angunit = OGC_NULL;
   double value;

   /*---------------------------------------------------------
    * sanity checks
    */
   if ( t == OGC_NULL )
   {
      ogc_error::set(err, OGC_ERR_WKT_EMPTY_STRING, obj_kwd());
      return OGC_NULL;
   }
   arr = t->_arr;

   if ( start < 0 || start >= t->_num )
   {
      ogc_error::set(err, OGC_ERR_WKT_INDEX_OUT_OF_RANGE, obj_kwd(), start);
      return OGC_NULL;
   }
   kwd = arr[start].str;

   if ( !is_kwd(kwd) )
   {
      ogc_error::set(err, OGC_ERR_WKT_INVALID_KEYWORD, obj_kwd(), kwd);
      return OGC_NULL;
   }

   /*---------------------------------------------------------
    * Get the level for this object,
    * the number of tokens at that level,
    * and the total number of tokens.
    */
   level = arr[start].lvl;
   for (end = start+1; end < t->_num; end++)
   {
      if ( arr[end].lvl <= level )
         break;
   }

   if ( pend != OGC_NULL )
      *pend = end;
   num = (end - start);

   for (same = 0; same < num; same++)
   {
      if ( arr[start+same+1].lvl != level+1 || arr[start+same+1].idx == 0 )
         break;
   }

   /*---------------------------------------------------------
    * There must be 1 token: MERIDIAN[ value ...
    */
   if ( same < 1 )
   {
      ogc_error::set(err, OGC_ERR_WKT_INSUFFICIENT_TOKENS, obj_kwd(), same);
      return OGC_NULL;
   }

   if ( same > 1 && get_strict_parsing() )
   {
      ogc_error::set(err, OGC_ERR_WKT_TOO_MANY_TOKENS,     obj_kwd(), same);
      return OGC_NULL;
   }

   start++;

   /*---------------------------------------------------------
    * Process all non-object tokens.
    * They come first and are syntactically fixed.
    */
   value = ogc_string::atod( arr[start++].str );

   /*---------------------------------------------------------
    * Now process all sub-objects
    */
   int  next = 0;
   for (int i = start; i < end; i = next)
   {
      if ( ogc_angunit::is_kwd(arr[i].str) )
      {
         if ( angunit != OGC_NULL )
         {
            ogc_error::set(err, OGC_ERR_WKT_DUPLICATE_UNIT, obj_kwd());
            bad = true;
         }
         else
         {
            angunit = ogc_angunit::from_tokens(t, i, &next, err);
            if ( angunit == OGC_NULL )
               bad = true;
         }
         continue;
      }

      /* unknown object, skip over it */
      for (next = i+1; next < end; next++)
      {
         if ( (arr[next].lvl <= arr[i].lvl) )
            break;
      }
   }

   /*---------------------------------------------------------
    * Create the object
    */
   if ( !bad )
   {
      obj = create(value, angunit, err);
   }

   if ( obj == OGC_NULL )
   {
      ogc_angunit :: destroy( angunit );
   }

   return obj;
}
示例#25
0
bool ogc_meridian :: is_kwd(const char * kwd)
{
   return ogc_string::is_equal(kwd, obj_kwd());
}
示例#26
0
/*------------------------------------------------------------------------
 * object from tokens
 */
ogc_time_origin * ogc_time_origin :: from_tokens(
   const ogc_token * t,
   int               start,
   int *             pend,
   ogc_error *       err)
{
   const ogc_token_entry * arr;
   const char * kwd;
   bool bad = false;
   int  level;
   int  same;
   int  end;
   int  num;

   ogc_time_origin * obj      = OGC_NULL;
   const char * origin;

   /*---------------------------------------------------------
    * sanity checks
    */
   if ( t == OGC_NULL )
   {
      ogc_error::set(err, OGC_ERR_WKT_EMPTY_STRING, obj_kwd());
      return OGC_NULL;
   }
   arr = t->_arr;

   if ( start < 0 || start >= t->_num )
   {
      ogc_error::set(err, OGC_ERR_WKT_INDEX_OUT_OF_RANGE, obj_kwd(), start);
      return OGC_NULL;
   }
   kwd = arr[start].str;

   if ( !is_kwd(kwd) )
   {
      ogc_error::set(err, OGC_ERR_WKT_INVALID_KEYWORD, obj_kwd(), kwd);
      return OGC_NULL;
   }

   /*---------------------------------------------------------
    * Get the level for this object,
    * the number of tokens at that level,
    * and the total number of tokens.
    */
   level = arr[start].lvl;
   for (end = start+1; end < t->_num; end++)
   {
      if ( arr[end].lvl <= level )
         break;
   }

   if ( pend != OGC_NULL )
      *pend = end;
   num = (end - start);

   for (same = 0; same < num; same++)
   {
      if ( arr[start+same+1].lvl != level+1 || arr[start+same+1].idx == 0 )
         break;
   }

   /*---------------------------------------------------------
    * There must be 2 tokens: TIMEEXTENT[ start, end ...
    */
   if ( same < 2 )
   {
      ogc_error::set(err, OGC_ERR_WKT_INSUFFICIENT_TOKENS, obj_kwd(), same);
      return OGC_NULL;
   }

   if ( same > 2 && get_strict_parsing() )
   {
      ogc_error::set(err, OGC_ERR_WKT_TOO_MANY_TOKENS,     obj_kwd(), same);
      return OGC_NULL;
   }

   start++;

   /*---------------------------------------------------------
    * Process all non-object tokens.
    * They come first and are syntactically fixed.
    */
   origin = arr[start++].str;

   /*---------------------------------------------------------
    * Now process all sub-objects
    */
#if 0 /* who cares? */
   int  next = 0;
   for (int i = start; i < end; i = next)
   {
      /* unknown object, skip over it */
      for (next = i+1; next < end; next++)
      {
         if ( (arr[next].lvl <= arr[i].lvl) )
            break;
      }
   }
#endif

   /*---------------------------------------------------------
    * Create the object
    */
   if ( !bad )
   {
      obj = create(origin, err);
   }

   if ( obj == OGC_NULL )
   {
   }

   return obj;
}
示例#27
0
bool ogc_bbox_extent :: is_kwd(const char * kwd)
{
   return ogc_string::is_equal(kwd, obj_kwd());
}
示例#28
0
bool ogc_time_origin :: is_kwd(const char * kwd)
{
   return ogc_string::is_equal(kwd, obj_kwd());
}
/*------------------------------------------------------------------------
 * object from tokens
 */
ogc_parameter * ogc_parameter :: from_tokens(
   const ogc_token * t,
   int               start,
   int *             pend,
   ogc_error *       err)
{
   const ogc_token_entry * arr;
   const char * kwd;
   bool bad = false;
   int  level;
   int  end;
   int  same;
   int  num;

   ogc_parameter * obj  = OGC_NULL;
   ogc_unit *      unit = OGC_NULL;
   ogc_id *        id   = OGC_NULL;
   ogc_vector *    ids  = OGC_NULL;
   const char * name;
   double       value;

   /*---------------------------------------------------------
    * sanity checks
    */
   if ( t == OGC_NULL )
   {
      ogc_error::set(err, OGC_ERR_WKT_EMPTY_STRING, obj_kwd());
      return OGC_NULL;
   }
   arr = t->_arr;

   if ( start < 0 || start >= t->_num )
   {
      ogc_error::set(err, OGC_ERR_WKT_INDEX_OUT_OF_RANGE, obj_kwd(), start);
      return OGC_NULL;
   }
   kwd = arr[start].str;

   if ( !ogc_string::is_equal(kwd, obj_kwd()) )
   {
      ogc_error::set(err, OGC_ERR_WKT_INVALID_KEYWORD, obj_kwd(), kwd);
      return OGC_NULL;
   }

   /*---------------------------------------------------------
    * Get the level for this object,
    * the number of tokens at that level,
    * and the total number of tokens.
    */
   level = arr[start].lvl;
   for (end = start+1; end < t->_num; end++)
   {
      if ( arr[end].lvl <= level )
         break;
   }

   if ( pend != OGC_NULL )
      *pend = end;
   num = (end - start);

   for (same = 0; same < num; same++)
   {
      if ( arr[start+same+1].lvl != level+1 || arr[start+same+1].idx == 0 )
         break;
   }

   /*---------------------------------------------------------
    * There must be 2 tokens: PARAMETER[ "name", value ...
    */
   if ( same < 2 )
   {
      ogc_error::set(err, OGC_ERR_WKT_INSUFFICIENT_TOKENS, obj_kwd(), same);
      return OGC_NULL;
   }

   if ( same > 2 && get_strict_parsing() )
   {
      ogc_error::set(err, OGC_ERR_WKT_TOO_MANY_TOKENS,     obj_kwd(), same);
      return OGC_NULL;
   }

   start++;

   /*---------------------------------------------------------
    * Process all non-object tokens.
    * They come first and are syntactically fixed.
    */
   name  = arr[start++].str;
   value = ogc_string::atod( arr[start++].str );

   /*---------------------------------------------------------
    * Now process all sub-objects
    */
   int  next = 0;
   for (int i = start; i < end; i = next)
   {
      if ( ogc_string::is_equal(arr[0].str, ogc_unit     ::obj_kwd()) ||
           ogc_string::is_equal(arr[0].str, ogc_angunit  ::obj_kwd()) ||
           ogc_string::is_equal(arr[0].str, ogc_lenunit  ::obj_kwd()) ||
           ogc_string::is_equal(arr[0].str, ogc_paramunit::obj_kwd()) ||
           ogc_string::is_equal(arr[0].str, ogc_scaleunit::obj_kwd()) ||
           ogc_string::is_equal(arr[0].str, ogc_timeunit ::obj_kwd()) )
      {
         if ( unit != OGC_NULL )
         {
            ogc_error::set(err, OGC_ERR_WKT_DUPLICATE_UNIT, obj_kwd());
            bad = true;
         }
         else
         {
            unit = ogc_unit::from_tokens(t, i, &next, err);
            if ( unit == OGC_NULL )
               bad = true;
         }
         continue;
      }

      if ( ogc_string::is_equal(arr[i].str, ogc_id::obj_kwd()) ||
           ogc_string::is_equal(arr[i].str, ogc_id::alt_kwd()) )
      {
         id = ogc_id::from_tokens(t, i, &next, err);
         if ( id == OGC_NULL )
         {
            bad = true;
         }
         else
         {
            if ( ids == OGC_NULL )
            {
               ids = ogc_vector::create(1, 1);
               if ( ids == OGC_NULL )
               {
                  ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
                  delete id;
                  bad = true;
               }
            }

            if ( ids != OGC_NULL )
            {
               void * p = ids->find(
                             id,
                             false,
                             ogc_utils::compare_id);
               if ( p != OGC_NULL )
               {
                  ogc_error::set(err, OGC_ERR_WKT_DUPLICATE_ID,
                     obj_kwd(), id->name());
                  delete id;
                  bad = true;
               }
               else
               {
                  if ( ids->add( id ) < 0 )
                  {
                     ogc_error::set(err, OGC_ERR_NO_MEMORY, obj_kwd());
                     delete id;
                     bad = true;
                  }
               }
            }
         }
         continue;
      }

      /* unknown object, skip over it */
      for (next = i+1; next < end; next++)
      {
         if ( (arr[next].lvl <= arr[i].lvl) )
            break;
      }
   }

   /*---------------------------------------------------------
    * Create the object
    */
   if ( !bad )
   {
      obj = create(name, value, unit, ids, err);
   }

   if ( obj == OGC_NULL )
   {
      ogc_unit   :: destroy( unit );
      ogc_vector :: destroy( ids  );
   }

   return obj;
}
bool ogc_base_geod_crs :: is_kwd(const char * kwd)
{
    return ogc_string::is_equal(kwd, obj_kwd());
}