Esempio n. 1
0
template<> NValue NValue::callUnary<FUNC_VOLT_POINTFROMTEXT>() const
{
    if (isNull()) {
        return NValue::getNullValue(VALUE_TYPE_POINT);
    }

    int32_t textLength;
    const char* textData = getObject_withoutNull(&textLength);
    std::string wkt(textData, textLength);

    // Discard whitespace, but return commas or parentheses as tokens
    Tokenizer tokens(wkt, boost::char_separator<char>(" \f\n\r\t\v", ",()"));
    Tokenizer::iterator it = tokens.begin();
    Tokenizer::iterator end = tokens.end();

    if (! boost::iequals(*it, "point")) {
        throwInvalidWktPoint(wkt);
    }
    ++it;

    if (! boost::iequals(*it, "(")) {
        throwInvalidWktPoint(wkt);
    }
    ++it;


    GeographyPointValue::Coord lng = stringToCoord(POINT, wkt, *it);
    ++it;

    GeographyPointValue::Coord lat = stringToCoord(POINT, wkt, *it);
    ++it;

    if ( lng < -180.0 || lng > 180.0) {
        throwInvalidPointLongitude(wkt);
    }

    if (lat < -90.0 || lat > 90.0 ) {
        throwInvalidPointLatitude(wkt);
    }

    if (! boost::iequals(*it, ")")) {
        throwInvalidWktPoint(wkt);
    }
    ++it;

    if (it != end) {
        throwInvalidWktPoint(wkt);
    }

    NValue returnValue(VALUE_TYPE_POINT);
    returnValue.getGeographyPointValue() = GeographyPointValue(lng, lat);

    return returnValue;
}
Esempio n. 2
0
// QC:G
GraphicalEffects Factory::loadEffects(TiXmlElement *xmlData) {
	GraphicalEffects effects;

	const char* aVal;
	bool b;
	int i;
	coord c;
	Rect r;
	Point p;

	if((aVal=xmlData->Attribute("effects"))) {
		effects.setEffects(aVal);
	}

	if(stringToPoint(xmlData->Attribute("scale"), p))
		effects.setScale(p);
		
	if(stringToPoint(xmlData->Attribute("sectionPointStart"), p))
		effects.setSectionPointStart(p);
	
	if(stringToPoint(xmlData->Attribute("sectionWidthHeight"), p))
		effects.setSectionWidthHeight(p);
	
	if(stringToRect(xmlData->Attribute("section"), r))
		effects.setSection(r);

	if(stringToCoord(xmlData->Attribute("rotation"), &c))
		effects.setRotation(c);

	if(stringToInt(xmlData->Attribute("opacity"), &i))
		effects.setOpacity(i);

	if(stringToInt(xmlData->Attribute("redFilter"), &i))
		effects.setIntegerEffect("RFIL", i);

	if(stringToInt(xmlData->Attribute("greenFilter"), &i))
		effects.setIntegerEffect("GFIL", i);

	if(stringToInt(xmlData->Attribute("blueFilter"), &i))
		effects.setIntegerEffect("BFIL", i);

	effects.setBlendMode(xmlData->Attribute("blend"));

	if(stringToBool(xmlData->Attribute("renderCache"), &b))
		effects.setRenderCache(b);
	
	if((aVal=xmlData->Attribute("preProcess"))) {
		effects.setPreProcess(aVal, NULL);
	}

	if((aVal=xmlData->Attribute("postProcess"))) {
		effects.setPostProcess(aVal, NULL);
	}

	return effects;
}
Esempio n. 3
0
static void readLoop(bool is_shell,
                     const std::string &wkt,
                     Tokenizer::iterator &it,
                     const Tokenizer::iterator &end,
                     S2Loop *loop)
{
    if (! boost::iequals(*it, "(")) {
        throwInvalidWktPoly("expected left parenthesis to start a loop");
    }
    ++it;

    std::vector<S2Point> points;
    while (it != end && *it != ")") {
        GeographyPointValue::Coord lng = stringToCoord(POLY, wkt, *it);

        if (lng < -180 || lng > 180) {
            throwInvalidPolygonLongitude(*it);
        }
        ++it;
        GeographyPointValue::Coord lat = stringToCoord(POLY, wkt, *it);
        if (lat < -90 || lat > 90) {
            throwInvalidPolygonLatitude(*it);
        }
        ++it;

        // Note: This is S2.  It takes latitude, longitude, not
        //       longitude, latitude.
        points.push_back(S2LatLng::FromDegrees(lat, lng).ToPoint());

        if (*it == ",") {
            ++it;
            // continue to next lat long pair
        }
        else if (*it != ")") {
            throwInvalidWktPoly("unexpected token: '" + (*it) + "'");
        }
    }

    if (it == end) {
        // we hit the end of input before the closing parenthesis
        throwInvalidWktPoly("unexpected end of input");
    }

    assert (*it == ")");

    // Advance iterator to next token
    ++it;

    if (points.size() < 4) {
        throwInvalidWktPoly("A polygon ring must contain at least 4 points (including repeated closing vertex)");
    }

    const S2Point& first = points.at(0);
    const S2Point& last = points.at(points.size() - 1);

    if (first != last) {
        throwInvalidWktPoly("A polygon ring's first vertex must be equal to its last vertex");
    }

    // S2 format considers the closing vertex in a loop to be
    // implicit, while in WKT it is explicit.  Remove the closing
    // vertex here to reflect this.
    points.pop_back();
    // The first is a shell.  All others are holes.  We need to reverse
    // the order of the vertices for holes.
    if (!is_shell) {
        // Don't touch the first point.  We don't want to
        // cycle the vertices.
        std::reverse(++(points.begin()), points.end());
    }
    loop->Init(points);
}