Esempio n. 1
0
void CIni::SerGetPoint(	bool bGet,CPoint	& pt,	LPCTSTR strEntry,	LPCTSTR strSection,	CPoint ptDefault)
{
	if(bGet)
		pt = GetPoint(strEntry,ptDefault,strSection);
	else
		WritePoint(strEntry,pt, strSection);
}
Esempio n. 2
0
OGRErr TigerPoint::CreateFeature( OGRFeature *poFeature,
                                  int pointIndex)

{
    char        szRecord[OGR_TIGER_RECBUF_LEN];
    OGRPoint    *poPoint = poFeature->GetGeometryRef()->toPoint();

    if( !SetWriteModule( m_pszFileCode, psRTInfo->nRecordLength+2, poFeature ) )
        return OGRERR_FAILURE;

    memset( szRecord, ' ', psRTInfo->nRecordLength );

    WriteFields( psRTInfo, poFeature, szRecord );

    if( poPoint != nullptr
        && (poPoint->getGeometryType() == wkbPoint
            || poPoint->getGeometryType() == wkbPoint25D) ) {
        WritePoint( szRecord, pointIndex, poPoint->getX(), poPoint->getY() );
    } else {
        if (bRequireGeom) {
            return OGRERR_FAILURE;
        }
    }

    WriteRecord( szRecord, psRTInfo->nRecordLength, m_pszFileCode );

    return OGRERR_NONE;
}
Esempio n. 3
0
void CIni::SerGetPoint( BOOL bGet,CPoint & pt, CString strEntry, LPCSTR strSection, CPoint ptDefault)
{
	if (bGet)
		pt = GetPoint(strEntry,ptDefault,strSection);
	else
		WritePoint(strEntry,pt, strSection);
}
Esempio n. 4
0
    void PathSerializer::WritePointsSequence(const PathCommand& cmd) {
        const vector<Point2F>& points = cmd.GetPoints();
        vector<Point2F>::const_iterator it;

        for (it = points.begin(); it != points.end(); ++it) {
            WritePoint(*it);
        }
    }
PyObject* Python::WriteContest(const ContestResult &result,
                               const ContestTraceVector &trace) {
  PyObject *py_trace = PyList_New(0);

  const ContestTracePoint *previous = NULL;
  for (auto i = trace.begin(), end = trace.end(); i != end; ++i) {
    PyObject *py_point = WritePoint(*i, previous);

    if (PyList_Append(py_trace, py_point))
      return NULL;

    Py_DECREF(py_point);
    previous = &*i;
  }

  return Py_BuildValue("{s:d,s:d,s:i,s:d,s:N}",
    "score", result.score,
    "distance", result.distance,
    "duration", (long)result.time,
    "speed", result.GetSpeed(),
    "turnpoints", py_trace);
}
Esempio n. 6
0
void
LoggerImpl::LogPoint(const NMEAInfo &gps_info)
{
  if (!gps_info.alive || !gps_info.time_available)
    return;

  if (writer == nullptr) {
    LogPointToBuffer(gps_info);
    return;
  }

  while (!pre_takeoff_buffer.empty()) {
    const struct PreTakeoffBuffer &src = pre_takeoff_buffer.shift();
    if (!simulator && !src.real)
      /* ignore buffered "unreal" fixes if we're logging a real
         flight; should never happen, but who knows */
      continue;

    NMEAInfo tmp_info;
    tmp_info.Reset();

    // NOTE: clock is only used to set the validity of valid objects to true
    //       for which "1" is sufficient. This kludge needs to be rewritten.
    tmp_info.clock = fixed(1);

    tmp_info.alive.Update(tmp_info.clock);

    if (src.location.IsValid()) {
      tmp_info.location = src.location;
      tmp_info.location_available.Update(tmp_info.clock);
    }

    if (src.gps_altitude_available) {
      tmp_info.gps_altitude = src.altitude_gps;
      tmp_info.gps_altitude_available.Update(tmp_info.clock);
    }

    if (src.pressure_altitude_available) {
      tmp_info.pressure_altitude = src.pressure_altitude;
      tmp_info.pressure_altitude_available.Update(tmp_info.clock);
    }

    tmp_info.date_time_utc = src.date_time_utc;
    tmp_info.time = src.time;
    tmp_info.time_available.Update(tmp_info.clock);

    tmp_info.gps.fix_quality = src.fix_quality;

    if (src.satellites_used_available) {
      tmp_info.gps.satellites_used_available.Update(tmp_info.clock);
      tmp_info.gps.satellites_used = src.satellites_used;
    }

    tmp_info.gps.hdop = src.hdop;
    tmp_info.gps.real = src.real;

    if (src.satellite_ids_available) {
      tmp_info.gps.satellite_ids_available.Update(tmp_info.clock);
      for (unsigned i = 0; i < GPSState::MAXSATELLITES; i++)
        tmp_info.gps.satellite_ids[i] = src.satellite_ids[i];
    }

    WritePoint(tmp_info);
  }

  WritePoint(gps_info);
}
Esempio n. 7
0
OGRErr TigerCompleteChain::CreateFeature( OGRFeature *poFeature )

{
    char        szRecord[OGR_TIGER_RECBUF_LEN];
    OGRLineString *poLine = (OGRLineString *) poFeature->GetGeometryRef();

    if( poLine == NULL 
        || (poLine->getGeometryType() != wkbLineString
            && poLine->getGeometryType() != wkbLineString25D) )
        return OGRERR_FAILURE;

    /* -------------------------------------------------------------------- */
    /*      Write basic data record ("RT1")                                 */
    /* -------------------------------------------------------------------- */
    if( !SetWriteModule( "1", psRT1Info->nRecordLength+2, poFeature ) )
        return OGRERR_FAILURE;
    memset( szRecord, ' ', psRT1Info->nRecordLength );
    WriteFields( psRT1Info, poFeature, szRecord );
    WritePoint( szRecord, 191, poLine->getX(0), poLine->getY(0) );
    WritePoint( szRecord, 210, 
                poLine->getX(poLine->getNumPoints()-1), 
                poLine->getY(poLine->getNumPoints()-1) );
    WriteRecord( szRecord, psRT1Info->nRecordLength, "1" );

    /* -------------------------------------------------------------------- */
    /*      Write geographic entity codes (RT3)                             */
    /* -------------------------------------------------------------------- */
    if (bUsingRT3) {
      memset( szRecord, ' ', psRT3Info->nRecordLength );
      WriteFields( psRT3Info, poFeature, szRecord );
      WriteRecord( szRecord, psRT3Info->nRecordLength, "3", fpRT3 );
    }

    /* -------------------------------------------------------------------- */
    /*      Write shapes sections (RT2)                                     */
    /* -------------------------------------------------------------------- */
    if( poLine->getNumPoints() > 2 )
    {
        int     nPoints = poLine->getNumPoints();
        int     iPoint, nRTSQ = 1;

        for( iPoint = 1; iPoint < nPoints-1; )
        {
            int         i;
            char        szTemp[5];

            memset( szRecord, ' ', psRT2Info->nRecordLength );

            WriteField( poFeature, "TLID", szRecord, 6, 15, 'R', 'N' );
            
            sprintf( szTemp, "%3d", nRTSQ );
            strncpy( ((char *)szRecord) + 15, szTemp, 4 );

            for( i = 0; i < 10; i++ )
            {
                if( iPoint < nPoints-1 )
                    WritePoint( szRecord, 19+19*i, 
                                poLine->getX(iPoint), poLine->getY(iPoint) );
                else
                    WritePoint( szRecord, 19+19*i, 0.0, 0.0 );

                iPoint++;
            }
            
            WriteRecord( szRecord, psRT2Info->nRecordLength, "2", fpShape );

            nRTSQ++;
        }
    }

    return OGRERR_NONE;
}
BOOL CDataIndex::CreateIndex(LPCTSTR DataFileName, int Format, int Width, int Height, int NumberOfPoints, double MinX, double MaxX, double MinY, double MaxY, double MinZ, double MaxZ, BOOL Optimize)
{
	if (m_HaveStarts) {
		delete [] m_CellStarts;
		m_HaveStarts = FALSE;
	}

	// create index for the given data file
	m_DataFileName = _T(DataFileName);

	// build index filename
	CFileSpec fs(DataFileName);
	fs.SetExt(".ldx");

	// populate header values
	strcpy(m_Header.Signature, "LDAindex");
	m_Header.Version = 1.1f;
	m_Header.Checksum = ComputeChecksum(DataFileName);
	m_Header.Format = Format;
	m_Header.MinX = 9999999999.0;
	m_Header.MinY = 9999999999.0;
	m_Header.MinZ = 9999999999.0;
	m_Header.MaxX = -9999999999.0;
	m_Header.MaxY = -9999999999.0;
	m_Header.MaxZ = -9999999999.0;
	m_Header.GridCellsAcross = Width;
	m_Header.GridCellsUp = Height;
	m_Header.TotalPointsIndexed = 0;

	// open data file
	CLidarData dat(DataFileName);
	LIDARRETURN pt;
	if (dat.IsValid()) {
		// create index file and write header
		m_FileHandle = fopen(fs.GetFullSpec(), "wb+");
		if (m_FileHandle) {
			if (WriteHeader()) {
				if (MinX + MaxX + MinY + MaxY + MinZ + MaxZ == 0.0) {
					// scan data file for min/max values
					while (dat.ReadNextRecord(&pt)) {
						m_Header.MinX = std::min(m_Header.MinX, pt.X);
						m_Header.MinY = std::min(m_Header.MinY, pt.Y);
						m_Header.MinZ = std::min(m_Header.MinZ, double(pt.Elevation));
						m_Header.MaxX = std::max(m_Header.MaxX, pt.X);
						m_Header.MaxY = std::max(m_Header.MaxY, pt.Y);
						m_Header.MaxZ = std::max(m_Header.MaxZ, double(pt.Elevation));

						m_Header.TotalPointsIndexed ++;
					}
					dat.Rewind();
				}
				else {
					// use values passed in
					m_Header.MinX = MinX;
					m_Header.MinY = MinY;
					m_Header.MinZ = MinZ;
					m_Header.MaxX = MaxX;
					m_Header.MaxY = MaxY;
					m_Header.MaxZ = MaxZ;


					m_Header.TotalPointsIndexed = NumberOfPoints;
				}

				// add 0.1 to max values to make sure we have a range that works for cell calculation
				// removed addition of 0.1 to header max values 3/21/2006
//				m_Header.MaxX += 0.1;
//				m_Header.MaxY += 0.1;
//				m_Header.MaxZ += 0.1;

				// modified cell size calculation to add 0.1 to max data values 3/21/2006
				double cellw = ((m_Header.MaxX + 0.1) - m_Header.MinX) / (double) m_Header.GridCellsAcross;
				double cellh = ((m_Header.MaxY + 0.1) - m_Header.MinY) / (double) m_Header.GridCellsUp;

				// read data file lines and build index
				int ptnum = 0;
				long offset = dat.GetPosition();
				while (dat.ReadNextRecord(&pt)) {
					ptnum ++;

					m_Point.Offset = offset;
					m_Point.Column = (unsigned char) ((pt.X - m_Header.MinX) / cellw);
					m_Point.Row = (unsigned char) ((pt.Y - m_Header.MinY) / cellh);
//						m_Point.PointNumber = ptnum;

					WritePoint();
					offset = dat.GetPosition();
				}

				// rewrite the header to get min/max values and number of points
				WriteHeader();

				// improve the index
				if (m_Header.TotalPointsIndexed && Optimize) {
					// allocate space for entire index
					INDEXENTRY* list = new INDEXENTRY[m_Header.TotalPointsIndexed];
					if (list) {
						// rewind to start of index entries
						fseek(m_FileHandle, 128, SEEK_SET);

						for (int i = 0; i < m_Header.TotalPointsIndexed; i ++) {
							ReadPoint();
							list[i].Column = m_Point.Column;
							list[i].Row = m_Point.Row;
							list[i].Offset = m_Point.Offset;
						}

						// sort list
						qsort(list, m_Header.TotalPointsIndexed, sizeof(INDEXENTRY), CompareIndexEntries);

						// re-write
						// rewind to start of index entries
						fseek(m_FileHandle, 128, SEEK_SET);

						for (int i = 0; i < m_Header.TotalPointsIndexed; i ++) {
							m_Point.Column = list[i].Column;
							m_Point.Row = list[i].Row;
							m_Point.Offset = list[i].Offset;
							WritePoint();
						}

						// create cell starting point file
						int colrow;
						m_CellStarts = new long[m_Header.GridCellsAcross * m_Header.GridCellsUp];
						if (m_CellStarts) {
							// initialize starting points
							for (int i = 0; i < m_Header.GridCellsAcross * m_Header.GridCellsUp; i ++)
								m_CellStarts[i] = -1;

							for (int i = 0; i < m_Header.TotalPointsIndexed; i ++) {
								colrow = list[i].Column * m_Header.GridCellsUp + list[i].Row;
								if (m_CellStarts[colrow] < 0)
									m_CellStarts[colrow] = i;
							}

							// write file
							CFileSpec ifs(fs.GetFullSpec());
							ifs.SetExt(".ldi");

							FILE* f = fopen(ifs.GetFullSpec(), "wb");
							if (f) {
								// use same header as index with slightly different signature
								strcpy(m_Header.Signature, "LDAstarts");
								fwrite(&m_Header, sizeof(header), 1, f);

								// seek to end of header area
								fseek(f, 128, SEEK_SET);

								// write starting points
								fwrite(m_CellStarts, sizeof(long), m_Header.GridCellsAcross * m_Header.GridCellsUp, f);

								fclose(f);

								// reset header to correct signature
								strcpy(m_Header.Signature, "LDAindex");
							}

							m_HaveStarts = TRUE;
						}

						delete [] list;
					}
				}
				fclose(m_FileHandle);

				// reopen in read mode and go to start of points
				m_FileHandle = fopen(fs.GetFullSpec(), "rb");
				fseek(m_FileHandle, 128, SEEK_SET);

				m_Valid = TRUE;
			}
		}
		dat.Close();
	}
	else {
		m_Valid = FALSE;
	}
	return(m_Valid);
}
void CDrawRuler::Save(CStream &archive)
{
	WritePoint(archive,a);
	archive << horiz;
}