Example #1
0
bool Data_Range::Add_Ranges (char *ranges)
{
    int low, high;
    double d1, d2;

    //---- check for special conditions ----

    if (ranges == NULL || *ranges == '\0' || *ranges == '\n') return (true);

    if (str_cmp (ranges, "All") == 0) {
        return (Add_Range (minimum, maximum, increment));
    }

    //---- unpack the range string ----

    while (ranges != NULL && *ranges != '\0' && *ranges != '\n') {

        ranges = Get_Range (ranges, &d1, &d2);

        if (d1 == 0.0 && d2 == 0.0) continue;

        low = (int) (d1 * factor);
        high = (int) (d2 * factor + 0.5);

        if (low > high || low < minimum || high > maximum) {
            if (Send_Messages ()) {
                exe->Error ("Range %g-%g is Out of Range", d1, d2);
            }
        }
        if (!Add_Range (low, high, increment)) return (false);
    }
    return (Num_Ranges () > 0);
}
Example #2
0
bool Data_Range::Add_Breaks (char *breaks)
{
    int low, high;
    double d1, d2;

    //---- check for special conditions ----

    if (breaks == NULL || *breaks == '\0' || *breaks == '\n') return (true);

    if (str_cmp (breaks, "None") == 0) {
        return (Add_Range (minimum, maximum));
    }

    //---- unpack the break string ----

    low = minimum;

    while (breaks != NULL && *breaks != '\0' && *breaks != '\n') {

        breaks = Get_Range (breaks, &d1, &d2);

        if (d1 == 0.0 && d2 == 0.0) continue;
        if (d2 > d1) goto break_error;

        high = (int) (d2 * factor + 0.5);

        if (low > high || low < minimum || high > maximum) goto break_error;

        if (low < high) {
            if (!Add_Range (low, high)) return (false);
        }
        low = high;
    }
    high = maximum;

    if (low < high) {
        return (Add_Range (low, high));
    }
    return (Num_Ranges () > 0);

break_error:
    if (Send_Messages ()) {
        exe->Error ("Range Breaks %s are Illogical", breaks);
    }
    return (false);
}
Example #3
0
bool Stop_Equiv::Read (bool report_flag)
{
	int num, len, count;
	double low, high;
	char *ptr;
	bool first;

	Group_Data *group;
	char buffer [40];

	Send_Messages (report_flag);
	report_flag = Send_Messages ();

	//---- read the link equiv ----

	if (report_flag) {
		exe->New_Page ();
		exe->Print (1, "Transit Stop Equivalence");
		exe->Print (1);
	}
	first = false;
	max_group = count = 0;

	while (Db_File::Read ()) {

		ptr = Clean_Record ();

		if (*ptr == '\0') continue;

		ptr = Get_Integer (ptr, &num);

		if (num == 0) continue;

		//---- check for a new group ----

		group = (Group_Data *) Get (&num);

		if (group == NULL) {
			group = (Group_Data *) New_Record (true);
			group->list = new Integer_List (10);
			group->group = num;
			Add ();
			first = true;
			if (num > max_group) max_group = num;
		} else {
			first = false;
		}

		//---- check for a label record ----

		ptr = Get_Integer (ptr, &num);

		if (num == 0) {
			while (*ptr == ' ' || *ptr == '\t') ptr++;

			len = (int) (strlen (ptr)) + 1;

			if (group->label != NULL) {
				delete [] group->label;
			}
			group->label = new char [len];
			
			if (group->label != NULL) {
				str_cpy (group->label, len, ptr);
			}
		}

		//---- create a default label ----

		if (group->label == NULL) {
			str_fmt (buffer, sizeof (buffer), "Stop Group %d", group->group);

			len = (int) (strlen (buffer)) + 1;
			
			group->label = new char [len];
			
			if (group->label != NULL) {
				str_cpy (group->label, len, buffer);
			}
		}

		if (report_flag && first) {
			exe->Print (1, "[%-25.25s] %3d = ", group->label, group->group);
			count = 0;
		}
		if (num == 0) continue;

		//---- process the equiv ranges ----

		while (ptr != NULL) {
			ptr = Get_Range (ptr, &low, &high);

			if (low == 0.0 && high == 0.0) continue;

			if (low > high) {
				if (Send_Messages ()) {
					exe->Write (1, "Stop Range %.0lf..%.0lf is Illogical", low, high); 
				}
				return (false);
			}
			if (report_flag) {
				if (count != 0) {
					if (count == 8) {
						exe->Print (1, "%34c", BLANK);
						count = 0;
					} else {
						exe->Print (0, ", ");
					}
				}
				count++;

				if (low != high) {
					exe->Print (0, "%.0lf..%.0lf", low, high);
				} else {
					exe->Print (0, "%.0lf", low);
				}
			}
			for (num = (int) low; num <= high; num++) {
				if (!group->list->Add (&num)) {
					if (Send_Messages ()) {
						exe->Write (2, "Insufficient Memory for Stop Group Data");
					}
					return (false);
				}
			}
		}
	}
	return (true);
}
//---------------------------------------------------------
bool CFilter_Morphology::On_Execute(void)
{
	int			x, y, ix, iy, Method;
	double		Minimum, Maximum;
	CSG_Grid	*pResult, Result;

	//-----------------------------------------------------
	m_pInput	= Parameters("INPUT")	->asGrid();
	pResult		= Parameters("RESULT")	->asGrid();
	m_Radius	= Parameters("RADIUS")	->asInt();
	Method		= Parameters("METHOD")	->asInt();

	//-----------------------------------------------------
	m_Kernel.Create(SG_DATATYPE_Byte, 1 + 2 * m_Radius, 1 + 2 * m_Radius);
	m_Kernel.Set_NoData_Value(0.0);
	m_Kernel.Assign(1.0);
	m_Kernel.Set_Value(m_Radius, m_Radius, 0.0);

	if( Parameters("MODE")->asInt() == 1 )
	{
		for(y=-m_Radius, iy=0; y<=m_Radius; y++, iy++)
		{
			for(x=-m_Radius, ix=0; x<=m_Radius; x++, ix++)
			{
				if( x*x + y*y > m_Radius*m_Radius )
				{
					m_Kernel.Set_Value(ix, iy, 0.0);
				}
			}
		}
	}

	//-----------------------------------------------------
	if( !pResult || pResult == m_pInput )
	{
		pResult	= SG_Create_Grid(m_pInput);
	}
	else
	{
		pResult->Set_Name(CSG_String::Format(SG_T("%s [%s]"), m_pInput->Get_Name(), Parameters("METHOD")->asString()));

		pResult->Set_NoData_Value(m_pInput->Get_NoData_Value());
	}

	//-----------------------------------------------------
	if( Method == 2 || Method == 3 )
	{
		Result.Create(*Get_System());

		for(y=0; y<Get_NY() && Set_Progress(y); y++)
		{
			for(x=0; x<Get_NX(); x++)
			{
				if( Get_Range(x, y, Minimum, Maximum) )
				{
					switch( Method )
					{
					case 2:	Result.Set_Value(x, y, Minimum);	break;	// Opening = Erosion + Dilation
					case 3:	Result.Set_Value(x, y, Maximum);	break;	// Closing = Dilation + Erosion
					}
				}
				else
				{
					Result.Set_NoData(x, y);
				}
			}
		}

		m_pInput	= &Result;
	}

	for(y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			if( Get_Range(x, y, Minimum, Maximum) )
			{
				switch( Method )
				{
				case 0: case 2:	pResult->Set_Value(x, y, Maximum);	break;	// Dilation
				case 1: case 3:	pResult->Set_Value(x, y, Minimum);	break;	// Erosion
				}
			}
			else
			{
				pResult->Set_NoData(x, y);
			}
		}
	}

	//-----------------------------------------------------
	if( !Parameters("RESULT")->asGrid() || Parameters("RESULT")->asGrid() == m_pInput )
	{
		m_pInput->Assign(pResult);

		delete(pResult);

		DataObject_Update(m_pInput);
	}

	m_Kernel.Destroy();

	return( true );
}