static void parse_coords_2 (struct gml_params *params) { /* parsing a list of coordinates (2) */ int count = 0; char coord[128]; double x; double y; char *p_out = coord; const char *p_in = params->CharData; int i; gaiaDynamicLinePtr dyn_line = gaiaAllocDynamicLine (); for (i = 0; i < params->CharDataLen; i++) { if (*p_in == ' ') { *p_out = '\0'; count++; if (count == 1) x = atof (coord); else y = atof (coord); p_out = coord; p_in++; if (count > 1) { gaiaAppendPointToDynamicLine (dyn_line, x, y); x = DBL_MAX; y = DBL_MAX; count = 0; } continue; } *p_out++ = *p_in++; } if (p_out != coord) { *p_out = '\0'; count++; if (count == 1) x = atof (coord); else y = atof (coord); gaiaAppendPointToDynamicLine (dyn_line, x, y); } if (params->is_point) add_point_to_geometry (params, dyn_line); if (params->is_linestring) add_linestring_to_geometry (params, dyn_line); if (params->is_polygon) { if (params->is_inner_boundary) add_interior_ring_to_geometry (params, dyn_line); else if (params->is_outer_boundary) add_exterior_ring_to_geometry (params, dyn_line); } }
static void kml_add_point_to_line (gaiaDynamicLinePtr dyn, double x, double y) { /* appending a point */ gaiaAppendPointToDynamicLine (dyn, x, y); }
GAIAGEO_DECLARE gaiaGeomCollPtr gaiaMakeEllipse (double cx, double cy, double x_axis, double y_axis, double step) { /* return a Linestring approximating an Ellipse */ gaiaDynamicLinePtr dyn; double x; double y; double angle = 0.0; int points = 0; gaiaPointPtr pt; gaiaGeomCollPtr geom; gaiaLinestringPtr ln; int iv = 0; if (step < 0.0) step *= -1.0; if (step == 0.0) step = 10.0; if (step < 0.1) step = 0.1; if (step > 45.0) step = 45.0; if (x_axis < 0.0) x_axis *= -1.0; if (y_axis < 0.0) y_axis *= -1.0; dyn = gaiaAllocDynamicLine (); while (angle < 360.0) { double rads = angle * .0174532925199432958; x = cx + (x_axis * cos (rads)); y = cy + (y_axis * sin (rads)); gaiaAppendPointToDynamicLine (dyn, x, y); angle += step; } /* closing the ellipse */ gaiaAppendPointToDynamicLine (dyn, dyn->First->X, dyn->First->Y); pt = dyn->First; while (pt) { /* counting how many points */ points++; pt = pt->Next; } if (points == 0) { gaiaFreeDynamicLine (dyn); return NULL; } geom = gaiaAllocGeomColl (); ln = gaiaAddLinestringToGeomColl (geom, points); pt = dyn->First; while (pt) { /* setting Vertices */ gaiaSetPoint (ln->Coords, iv, pt->X, pt->Y); iv++; pt = pt->Next; } gaiaFreeDynamicLine (dyn); return geom; }
GAIAGEO_DECLARE gaiaGeomCollPtr gaiaMakeEllipticArc (double cx, double cy, double x_axis, double y_axis, double start, double stop, double step) { /* return a Linestring approximating an Elliptic Arc */ gaiaDynamicLinePtr dyn; double x; double y; double angle; double rads; int points = 0; gaiaPointPtr pt; gaiaGeomCollPtr geom; gaiaLinestringPtr ln; int iv = 0; if (step < 0.0) step *= -1.0; if (step == 0.0) step = 10.0; if (step < 0.1) step = 0.1; if (step > 45.0) step = 45.0; if (x_axis < 0.0) x_axis *= -1.0; if (y_axis < 0.0) y_axis *= -1.0; /* normalizing Start/Stop angles */ while (start >= 360.0) start -= 360.0; while (start <= -720.0) start += 360; while (stop >= 360.0) stop -= 360.0; while (stop <= -720.0) stop += 360; if (start < 0.0) start = 360.0 + start; if (stop < 0.0) stop = 360.0 + stop; if (start > stop) stop += 360.0; dyn = gaiaAllocDynamicLine (); angle = start; while (angle < stop) { rads = angle * .0174532925199432958; x = cx + (x_axis * cos (rads)); y = cy + (y_axis * sin (rads)); gaiaAppendPointToDynamicLine (dyn, x, y); angle += step; } /* closing the arc */ rads = stop * .0174532925199432958; x = cx + (x_axis * cos (rads)); y = cy + (y_axis * sin (rads)); if (x != dyn->Last->X || y != dyn->Last->Y) gaiaAppendPointToDynamicLine (dyn, x, y); pt = dyn->First; while (pt) { /* counting how many points */ points++; pt = pt->Next; } if (points == 0) { gaiaFreeDynamicLine (dyn); return NULL; } geom = gaiaAllocGeomColl (); ln = gaiaAddLinestringToGeomColl (geom, points); pt = dyn->First; while (pt) { /* setting Vertices */ gaiaSetPoint (ln->Coords, iv, pt->X, pt->Y); iv++; pt = pt->Next; } gaiaFreeDynamicLine (dyn); return geom; }
static gaiaDynamicLinePtr auxGridSnapRing (gaiaRingPtr rng, double origin_x, double origin_y, double origin_z, double origin_m, double size_x, double size_y, double size_z, double size_m) { /* snapping a Ring to a regular Grid */ double x; double y; double z; double m; int has_z = 0; int has_m = 0; int iv; gaiaDynamicLinePtr dyn; gaiaPointPtr pt0; gaiaPointPtr pt; int count = 0; if (rng == NULL) return NULL; if (rng->DimensionModel == GAIA_XY_Z || rng->DimensionModel == GAIA_XY_Z_M) has_z = 1; if (rng->DimensionModel == GAIA_XY_M || rng->DimensionModel == GAIA_XY_Z_M) has_m = 1; dyn = gaiaAllocDynamicLine (); for (iv = 0; iv < rng->Points; iv++) { /* snapping each Vertex to the given grid */ int to_be_inserted = 0; z = 0.0; m = 0.0; if (has_z && has_m) { gaiaGetPointXYZM (rng->Coords, iv, &x, &y, &z, &m); } else if (has_z) { gaiaGetPointXYZ (rng->Coords, iv, &x, &y, &z); } else if (has_m) { gaiaGetPointXYM (rng->Coords, iv, &x, &y, &m); } else { gaiaGetPoint (rng->Coords, iv, &x, &y); } /* snapping coords to the given grid */ if (size_x > 0.0) x = rint ((x - origin_x) / size_x) * size_x + origin_x; if (size_y > 0.0) y = rint ((y - origin_y) / size_y) * size_y + origin_y; if (has_z && size_z > 0.0) z = rint ((z - origin_z) / size_z) * size_z + origin_z; if (has_m && size_m > 0.0) m = rint ((m - origin_m) / size_m) * size_m + origin_m; if (dyn->Last == NULL) to_be_inserted = 1; else { /* skipping repeated points */ pt = dyn->Last; if (has_z && has_m) { if (pt->X == x && pt->Y == y && pt->Z == z && pt->M == m) ; else to_be_inserted = 1; } else if (has_z) { if (pt->X == x && pt->Y == y && pt->Z == z) ; else to_be_inserted = 1; } else if (has_m) { if (pt->X == x && pt->Y == y && pt->M == m) ; else to_be_inserted = 1; } else { if (pt->X == x && pt->Y == y) ; else to_be_inserted = 1; } } if (to_be_inserted) { if (has_z && has_m) gaiaAppendPointZMToDynamicLine (dyn, x, y, z, m); else if (has_z) gaiaAppendPointZToDynamicLine (dyn, x, y, z); else if (has_m) gaiaAppendPointMToDynamicLine (dyn, x, y, m); else gaiaAppendPointToDynamicLine (dyn, x, y); } } /* ensuring for Ring closure */ pt0 = dyn->First; pt = dyn->Last; if (has_z && has_m) { if (pt0->X == pt->X && pt0->Y == pt->Y && pt0->Z == pt->Z && pt0->M == pt->M) ; else gaiaAppendPointZMToDynamicLine (dyn, pt->X, pt->Y, pt->Z, pt->M); } else if (has_z) { if (pt0->X == pt->X && pt0->Y == pt->Y && pt0->Z == pt->Z) ; else gaiaAppendPointZToDynamicLine (dyn, pt->X, pt->Y, pt->Z); } else if (has_m) { if (pt0->X == pt->X && pt0->Y == pt->Y && pt0->M == pt->M) ; else gaiaAppendPointMToDynamicLine (dyn, pt->X, pt->Y, pt->M); } else { if (pt0->X == pt->X && pt0->Y == pt->Y) ; else gaiaAppendPointToDynamicLine (dyn, pt->X, pt->Y); } /* checking for validity */ pt = dyn->First; while (pt) { /* counting how many points are there */ count++; pt = pt->Next; } if (count < 4) { /* skipping any collapsed ring */ gaiaFreeDynamicLine (dyn); return NULL; } return dyn; }
static void auxGridSnapLinestring (gaiaLinestringPtr ln, gaiaGeomCollPtr result, double origin_x, double origin_y, double origin_z, double origin_m, double size_x, double size_y, double size_z, double size_m) { /* snapping a Linestring to a regular Grid */ double x; double y; double z; double m; int has_z = 0; int has_m = 0; int iv; gaiaDynamicLinePtr dyn; gaiaPointPtr pt; gaiaLinestringPtr lnx; int count = 0; if (ln == NULL || result == NULL) return; if (ln->DimensionModel == GAIA_XY_Z || ln->DimensionModel == GAIA_XY_Z_M) has_z = 1; if (ln->DimensionModel == GAIA_XY_M || ln->DimensionModel == GAIA_XY_Z_M) has_m = 1; dyn = gaiaAllocDynamicLine (); for (iv = 0; iv < ln->Points; iv++) { /* snapping each Vertex to the given grid */ int to_be_inserted = 0; z = 0.0; m = 0.0; if (has_z && has_m) { gaiaGetPointXYZM (ln->Coords, iv, &x, &y, &z, &m); } else if (has_z) { gaiaGetPointXYZ (ln->Coords, iv, &x, &y, &z); } else if (has_m) { gaiaGetPointXYM (ln->Coords, iv, &x, &y, &m); } else { gaiaGetPoint (ln->Coords, iv, &x, &y); } /* snapping coords to the given grid */ if (size_x > 0.0) x = rint ((x - origin_x) / size_x) * size_x + origin_x; if (size_y > 0.0) y = rint ((y - origin_y) / size_y) * size_y + origin_y; if (has_z && size_z > 0.0) z = rint ((z - origin_z) / size_z) * size_z + origin_z; if (has_m && size_m > 0.0) m = rint ((m - origin_m) / size_m) * size_m + origin_m; if (dyn->Last == NULL) to_be_inserted = 1; else { /* skipping repeated points */ pt = dyn->Last; if (has_z && has_m) { if (pt->X == x && pt->Y == y && pt->Z == z && pt->M == m) ; else to_be_inserted = 1; } else if (has_z) { if (pt->X == x && pt->Y == y && pt->Z == z) ; else to_be_inserted = 1; } else if (has_m) { if (pt->X == x && pt->Y == y && pt->M == m) ; else to_be_inserted = 1; } else { if (pt->X == x && pt->Y == y) ; else to_be_inserted = 1; } } if (to_be_inserted) { if (has_z && has_m) gaiaAppendPointZMToDynamicLine (dyn, x, y, z, m); else if (has_z) gaiaAppendPointZToDynamicLine (dyn, x, y, z); else if (has_m) gaiaAppendPointMToDynamicLine (dyn, x, y, m); else gaiaAppendPointToDynamicLine (dyn, x, y); } } /* checking for validity */ pt = dyn->First; while (pt) { /* counting how many points are there */ count++; pt = pt->Next; } if (count < 2) { /* skipping any collapsed line */ gaiaFreeDynamicLine (dyn); return; } /* inserting into the result Geometry */ lnx = gaiaAddLinestringToGeomColl (result, count); iv = 0; pt = dyn->First; while (pt) { /* copying points */ if (lnx->DimensionModel == GAIA_XY_Z) { gaiaSetPointXYZ (lnx->Coords, iv, pt->X, pt->Y, pt->Z); } else if (lnx->DimensionModel == GAIA_XY_M) { gaiaSetPointXYM (lnx->Coords, iv, pt->X, pt->Y, pt->M); } else if (lnx->DimensionModel == GAIA_XY_Z_M) { gaiaSetPointXYZM (lnx->Coords, iv, pt->X, pt->Y, pt->Z, pt->M); } else { gaiaSetPoint (lnx->Coords, iv, pt->X, pt->Y); } iv++; pt = pt->Next; } gaiaFreeDynamicLine (dyn); }