Posts

Showing posts with the label Buffer

C Char Array Initialization

Answer : This is not how you initialize an array, but for: The first declaration: char buf[10] = ""; is equivalent to char buf[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; The second declaration: char buf[10] = " "; is equivalent to char buf[10] = {' ', 0, 0, 0, 0, 0, 0, 0, 0, 0}; The third declaration: char buf[10] = "a"; is equivalent to char buf[10] = {'a', 0, 0, 0, 0, 0, 0, 0, 0, 0}; As you can see, no random content: if there are fewer initializers, the remaining of the array is initialized with 0 . This the case even if the array is declared inside a function. Edit: OP (or an editor) silently changed some of the single quotes in the original question to double quotes at some point after I provided this answer. Your code will result in compiler errors. Your first code fragment: char buf[10] ; buf = '' is doubly illegal. First, in C, there is no such thing as an empty char . You can use double quote...

C++: Store Read Binary File Into Buffer

Answer : I just want to mention that there is a standard way to read from a binary file into a buffer. Using <cstdio> : char buffer[BUFFERSIZE]; FILE * filp = fopen("filename.bin", "rb"); int bytes_read = fread(buffer, sizeof(char), BUFFERSIZE, filp); Using <fstream> : std::ifstream fin("filename.bin", ios::in | ios::binary ); fin.read(buffer, BUFFERSIZE); What you do with the buffer afterwards is all up to you of course. Edit: Full example using <cstdio> #include <cstdio> const int BUFFERSIZE = 4096; int main() { const char * fname = "filename.bin"; FILE* filp = fopen(fname, "rb" ); if (!filp) { printf("Error: could not open file %s\n", fname); return -1; } char * buffer = new char[BUFFERSIZE]; while ( (int bytes = fread(buffer, sizeof(char), BUFFERSIZE, filp)) > 0 ) { // Do something with the bytes, first elements of buffer. // For exa...

Buffering Line With Flat Cap Style Using GeoPandas?

Answer : GeoPandas isn't passing through all arguments to the shapely buffer method. Instead you can use the standard pandas apply method to call buffer on each geometry individually, e.g.: # Assumes that geometry will be the geometry column capped_lines = df.geometry.apply(lambda g: g.buffer(100, cap_style=2)) Also, not that this returns a GeoPandas GeoSeries object, so if you need the attributes (and projection for that matter, though that may be an outstanding issue) you'll need to overwite the geometry column in the original GeoDataFrame. GeoPandas now pass kwargs to shapely, so you can do below now: gdf.geometry.to_crs("epsg:3857").buffer(10, cap_style=2) PR: https://github.com/geopandas/geopandas/pull/535 Update: reason for change crs to 3857 is control on buffer radius in meter, else geopandas raise below warning: UserWarning: Geometry is in a geographic CRS. Results from 'buffer' are likely incorrect. Use 'GeoSeries.to_crs()' to ...